MATLAB Answers


¿How to change title of plot while using quoted text, variables, multilines and Fontsize?

Asked by Gonzalo Lerner on 1 Jun 2017
Latest activity Commented on by dpb
on 6 Jun 2017
Accepted Answer by dpb
I can make it work separetly but not on the same title. This is what I have now and it's working.
title ([ suj '.' iniciales_cell(suj) 'Grupo' grupo],'fontsize',17);
But now I want to put what's in bold in the first line and what's in italic on the second line.
suj '.' iniciales_cell(suj) Line 1
'Grupo' grupo Line 2
How can I do this?? I tried with {} but i can't make it work with the fontsize and all.
Thanks in advance


Sign in to comment.

1 Answer

Answer by dpb
on 1 Jun 2017
Edited by dpb
on 2 Jun 2017
 Accepted Answer

hTl=title({'\bfLine 1';'\rmLine 2'},'fontsize',17);
Addendum Missed the 'quoted' string--you just have to "double-up" to embed a single quote in a quoted string:
hTl=title({'\bf''Line 1''';'\rm''Line 2'''},'fontsize',17);


Show 1 older comment
Well, that's a problem in sizes of character arrays; note the above uses cell strings; then the two strings can be different lengths, but the usual rules hold if you try to catenate character arrays. char can help syntactically in that regard sometimes although I find it's generally just as clear/easy to just "use the curlies, Luke!" as below.
Modify the above for variables and different lengths...
t1='Line 1';
t2='Second Line';
hTl=title({['\bf''' t1 ''''];['\rm\it''' t2 '''']},'fontsize',17);
It's not quite so confusing counting the ticks if you incorporate them into the text itself--
t1='''Line 1''';
t2='''Second Line''';
hTl=title({['\bf' t1];['\rm\it' t2]},'fontsize',17);
Both of those yield
Thank you very much!! You made it very clear!
Glad to's easy to get lost in the forest of tick marks in stuff like this and what is really pretty simple just gets messy enough it's hard to figure out where went wrong.

Sign in to comment.