问题
In Matlab R2016b, displaying variables of certain data types shows information about the type. This happens when the variable is displayed by typing it without a final semicolon (it doesn't happen when using the disp
function).
Compare for example:
Matlab R2015b (old format: displays just the data):
>> x = [10 20 30] x = 10 20 30 >> x = {10 20 30} x = [10] [20] [30] >> x = [false false true] x = 0 0 1
Matlab R2016b (new format: includes type):
>> x = [10 20 30] x = 10 20 30 >> x = {10 20 30} x = 1×3 cell array [10] [20] [30] >> x = [false false true] x = 1×3 logical array 0 0 1
As you see, there's an extra line in R2016b telling the type. Apparently this happens for any type that is not double
or char
.
Is there some setting in R2016b to go back to the old behaviour?
回答1:
Unfortunately there doesn't seem to be a preference for changing that behavior. There is (as always) a bit of a hacky workaround.
When you omit a semi-colon from a line, it's not disp
that is called but rather display. R2016b has apparently modified the display
method for a cell
datatype to display some type information along with the values themselves.
Thankfully we can overload that display
method with something that looks a little bit more like the display
of previous releases.
We can create a @cell
folder (anywhere on our path) and place a file called display.m
inside.
@cell/display.m
function display(obj)
% Overloaded display function for grumpy old men
if strcmpi(get(0, 'FormatSpacing'), 'loose')
fprintf('\n%s =\n\n', inputname(1))
else
fprintf('%s =\n', inputname(1))
end
disp(obj);
end
Now, whenever a cell array is displayed due lack of a trailing semi-colon, it will not include any type information.
>> c = {'a', 'b'}
c =
'a' 'b'
Unfortunately, there are other datatypes (such as logical
) that also display the type information so you'd have to overload the display
method for each of these classes.
来源:https://stackoverflow.com/questions/39828222/back-to-old-display-format-in-matlab-r2016b