Break in the title

How can I break this title into multiple lines? The other examples on mathworks mostly deal with sentences in the title or may be I missed something! Thanks.
str= {' Parameters:',['S_0=' num2str(S0),', I_0=' num2str(I0),', C_0=' num2str(R10),', A_0=' num2str(R20)...
', \alpha=' num2str(alpha),', p_1=' num2str(p1),', q_2=' num2str(p2),', p_3=' num2str(p3),', p_4=' num2str(p4),', p_5=' num2str(p5) ...
', b=' num2str(b),', a=' num2str(a),', d_a=' num2str(da),', d_i=' num2str(di), ', d_h=' num2str(dh)...
', g=' num2str(g),', m=' num2str(m),', b_s=' num2str(bs),', F=' num2str(F)
]
};

Respuestas (1)

jonas
jonas el 25 de Ag. de 2018
Editada: jonas el 25 de Ag. de 2018

0 votos

Use sprintf to reduce the number of num2str and make the coding easier. For example:
str= {' Parameters:',['S_0=' num2str(S0),', I_0=' num2str(I0),', C_0=' num2str(R10),', A_0=' num2str(R20)...
', \alpha=' num2str(alpha)}
can be written in two lines as:
str=sprintf('Parameters: [S_0=%g, I_0=%g, C_0=%g, A_0=%g, \n \\alph=%g',S0,I0,R10,R20,alpha)
Note the \n for newline character
If you still want to use a cell array, then you can make a break as follows
str={'line 1';'line 2'}

4 comentarios

Rose
Rose el 25 de Ag. de 2018
Thanks for your help. Previously, I was using these parameters to make a text box in a figure (see code below). Would it be possible to do the same thing with sprintf?
str= {' Parameters:',['S_0=' num2str(S0),', I_0=' num2str(I0),', C_0=' num2str(R10),', A_0=' num2str(R20)...
', \alpha=' num2str(alpha),', p_1=' num2str(p1),', q_2=' num2str(p2),', p_3=' num2str(p3),', p_4=' num2str(p4),', p_5=' num2str(p5) ...
', b=' num2str(b),', a=' num2str(a),', d_a=' num2str(da),', d_i=' num2str(di), ', d_h=' num2str(dh)...
', g=' num2str(g),', m=' num2str(m),', b_s=' num2str(bs),', F=' num2str(F)
]
};
annotation('textbox',...
[0.15 0.35 0.8 0.25],...
'String',str,...
'FontSize',14,...
'FontName','Arial',...
'LineStyle','-',...
'EdgeColor','k',...
'LineWidth',2,...
'BackgroundColor',[1 1 1],...
'Color',[0 0 0],'FitBoxToText','on');
jonas
jonas el 25 de Ag. de 2018
Editada: jonas el 25 de Ag. de 2018
The output of sprintf is just a string. So yes, it is possible. Perhaps there are some circumstances when a cell array is a better way to store a multi-line string, but I can't think of any.
Try this simple example:
str=sprintf('A%g\nB%g',1,2)
annotation('textbox',[0 0 .1 .1],'string',str)
Stephen23
Stephen23 el 26 de Ag. de 2018
Editada: Stephen23 el 26 de Ag. de 2018
" Perhaps there are some circumstances when a cell array is a better way to store a multi-line string, but I can't think of any"
Cell arrays make it trivial to use indexing to select which lines get displayed. For example, I used this for the warning text in cubehelix_view:
jonas
jonas el 26 de Ag. de 2018
True, that's one example
Another nice FEX function added to my arsenal. Already using your colorbrewer and matplotlib. They really make life easier when producing figures for scientific papers, so thanks for those!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Ag. de 2018

Comentada:

el 26 de Ag. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by