How can I change the text color within a multi-line cell array

10 views (last 30 days)
I'm adding multi-line text to a plot using a cell array and the text command. I can change font attributes like bold and italics but I need to change the color of one line.
label(4) in the code below needs to be bold (no problem there) but I'd like it to be red as well. Putting attributes in the cell like this ... ['\bfTarget Length Met','color','r'] gives me an error.
label(1)={['S = ',num2str(compliance,formatSpec),' mm/kN']};
label(2)={['R^2 = ',num2str(rsq)]};
label(3)={['a = ',num2str(acur)]};
label(4)={['\bfTarget Length Met']};
text_xplace=min(cmod)+(max(cmod)-min(cmod))/10;
text_yplace=f_max-(f_max-min(force))/4;
text(text_xplace, text_yplace,(label))
Any one got a solution?

Accepted Answer

Joseph Cheng
Joseph Cheng on 27 Mar 2014
Edited: Joseph Cheng on 27 Mar 2014
If you look at the documentation for text() you can see an example, i pasted it below.
text(.1,.5,['\fontsize{16}black '...
'{\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal '...
'\color{red}red} black again'])
oh its late so i didn't read it carefully. you'll have to do the that during the plotting phase.
  2 Comments
Dash
Dash on 27 Mar 2014
I've tried several attempts at the syntax and was met with error messages. This one worked. Thanks so much for reply!
label(4)={['\color{red}','\bfTarget Length Met']};
Joseph Cheng
Joseph Cheng on 27 Mar 2014
wait i think i did answer it... it is confusing as you did say " I can change font attributes like bold and italics but I need to change the color of one line." but later you say text color.
if you want to swap out the color of a line you'll have to do something like here and set which line set(hline(2),'Color', ) into something

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!