Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a warning message over multiple lines

Tags:

matlab

I am trying to print a warning message that is a little long and includes 2 variable calls. Here's my code:

warning( 'MATLAB:questionable_argument', ...
           'the arguments dt (%d) and h (%d) are sub-optimal. Consider increasing nt or decreasing nx.', ...
           dt, h )

Obviously, the line of text extends to the right when viewing the MATLAB code. How can I break it so it wraps nicely? I've tried multiple things but keep getting syntax errors.

like image 617
Alex Willerth Avatar asked Sep 02 '25 10:09

Alex Willerth


1 Answers

As suggested in comments, just insert a \n where you want to break the line. You can also use a variable for the text, to make it easy to read also within the code:

txt = sprintf(['the arguments dt (%d) and h (%d) are sub-optimal.\n'... 
    'Consider increasing nt or decreasing nx.'],dt,h);
warning( 'MATLAB:questionable_argument',txt)
like image 74
EBH Avatar answered Sep 05 '25 08:09

EBH