valerio_sperati
valerio_sperati

Reputation: 823

Matlab and string latex format

In Matlab, I need to format a latex string containing a numeric variable. The string is like: foo1 , where 1 is contained in variable X and must be subscript.

This line works if I write directly the value of variable

str = texlabel('foo_{1}')

I'm wondering how to insert the X instead of the value. In fact this line

str = texlabel('foo_{X}')'

produce, of course, fooX Thanks

Upvotes: 1

Views: 1210

Answers (1)

sco1
sco1

Reputation: 12214

The quickest method would be to include a call to sprintf:

X = 1;
str = texlabel(sprintf('foo_{%u}', X));

Which returns:

str =

{foo}_{{2}}

Which we can plot real quick with text(0.1, 0.1, str):

yay

Upvotes: 3

Related Questions