I have a m-file that outputs some calculations basically this:
disp(['Value ', num2str(i)]);
disp(x)
disp(['Number of iterations ', num2str(iter)])
disp('----------')
However this ouputs stuff rather messy in the command view which is really irritating when debugging the code. I would like to add a couple of line breaks to the output in the command window. However I can't seem to find any information about this, as the Matlab documentation is pretty awful. I've tried stuff like disp('\n') and disp(' ') to no avail.
How do you do it? Can it be done?
c = newline creates a newline character. newline is equivalent to char(10) or sprintf('\n') . Use newline to concatenate a newline character onto a character vector or a string, or to split text on newline characters.
To display text in the Command Window, use disp or fprintf.
fprintf('\n') underneath the line you're trying to make a space for.
fprintf('\n')
should do the trick, likewise disp(' ')
. In general, fprintf
is more flexible than disp
. The main advantage of disp
is that it has some intelligence and knows how to print out complete objects.
You can also disp a the line break character '\n' with its decimal value: 10.
disp(char(10))
or
disp(['line 1' char(10) 'line 2'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With