Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you output a line break in the command view in Matlab when running a m-file?

Tags:

matlab

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?

like image 442
Reed Richards Avatar asked Sep 17 '09 08:09

Reed Richards


People also ask

How do you show line breaks in MATLAB?

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.

How do I display the output Command Window in MATLAB?

To display text in the Command Window, use disp or fprintf.

How do you print a blank line in MATLAB?

fprintf('\n') underneath the line you're trying to make a space for.


2 Answers

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.

like image 174
Edric Avatar answered Sep 17 '22 17:09

Edric


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'])
like image 25
Mike Katz Avatar answered Sep 21 '22 17:09

Mike Katz