此代碼只是確定如何顯示取決於t
類型以及當前format
設置的可變t
值。
% If this is a PhArea instance
if isa(t, 'PhArea)
% Then just display it
disp(t)
% If the user has enabled compact formatting (format compact)
elseif isequal(get(0, 'formatspacing'), 'compact')
% Display the variable's name and an equal sign (no spaces)
disp([inputname(1), '='])
% Display the variable itself
disp(t)
% Otherwise
else
% Display an empty line
disp(' ')
% Display the variable's name and an equal sign (with space)
disp([inputname(1), ' ='])
% Display an empty line
disp(' ')
% Display the variable
disp(t)
end
更新
下面一行是這裏最棘手的。
isequal(get(0, 'formatspacing'), 'compact')
這是做什麼檢索當前format spacing。 0
是用於存儲適用於給定MATLAB會話的信息的圖形root object。當用戶指定他們想要使用'compact'
格式間隔時,此配置存儲在根對象內。
format loose
get(0, 'formatspacing')
% loose
format compact
get(0, 'formatspacing')
% compact
因此通過檢索當前設置爲一個字符串,然後你可以比較一下(用isequal
),以'compact'
,看看如果用戶需要使用緊湊的格式間距與否。
請將代碼發佈到您的問題中,並且不要附上屏幕截圖 – Suever
@Suever它已完成 – chsafouane
通過所有方法來看看一段代碼所做的是最好的方式來運行它。請看看調試器,http://se.mathworks.com/help/matlab/debugging-code.html – patrik