MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by noa
on 20 Sep 2012

hi. i want to make a text annotation including this text:

eval(['text1=''\underline{Row #', num2str(j), '}'';']) annotation('textbox', [a b c d] , 'String', text1, 'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center', 'Color', 'k', 'EdgeColor', 'k', 'BackgroundColor', 'white', 'FontWeight', 'bold', 'FontSize', 15, 'interpreter','latex');

i get an error: Warning: Unable to interpret LaTeX string "\underline{Row #1}"

how can i solve this?

thanks. Noa

*No products are associated with this question.*

Answer by Matt Fig
on 20 Sep 2012

Edited by Matt Fig
on 20 Sep 2012

First of all you really should learn to use SPRINTF instead of EVAL. Please look at the help for SPRINTF and do not use EVAL in your code.

J = 5; text1 = sprintf('$$\\underline{Row\\#\\;%i }$$',J); text(.5,.5,text1,'interpreter','latex')

Or if J is a floating point number and not an integer:

J = 5.34; text1 = sprintf('$$\\underline{Row\\#\\;%2.2f }$$',J); text(.5,.5,text1,'interpreter','latex')

Answer by Jan Simon
on 20 Sep 2012

Edited by Jan Simon
on 20 Sep 2012

In http://www.mathworks.com/matlabcentral/answers/28189 you find

text(0.5, 0.5, '\underline{Hello World}','interp','latex')

I cannot test this currently, but Daniel's answer sounds, like this is not working.

## 5 Comments

## noa

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48635#comment_100343

nope, i googled it and that is the answer that it gave... how can i underline?

## Jan Simon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48635#comment_100351

Btw. Please do you the favour and omit the

eval(). Simply type:## noa

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48635#comment_100353

Warning: Invalid escape sequence appears in format string. See help sprintf for valid escape sequences

## Matt Fig

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48635#comment_100362

Jan, it should be:

But there is more to it than that. See my answer below.

## Jan Simon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/48635#comment_100367

@noa: And? Did you follow the advice to read "help sprintf" to find out, that a \\ is required to create a \ in the output string? Or do you try that it is my turn to find this out?

@Matt: Thanks.