[Solved] What is the reasonable way to display matrix size? [closed]


If you wanted to be real fancy, you could write an anonymous function to do this since you can then use inputname to infer the name of the input variable.

func = @(var)fprintf('\n%s size: %s\n', inputname(1), num2str(size(var)))

x = rand(10, 4);

func(x)
%   x size: 10   4

You can also just use fprintf

fprintf('\n%s size: %s\n', 'myvar', num2str(size(myvar)))

Or if you don’t want to use num2str you can instead use multiple lines

fprintf('\n%s size: ', 'myvar')
fprintf('%d ', size(myvar))
fprintf('\n')

1

solved What is the reasonable way to display matrix size? [closed]