Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass variables into my title with Latex Interpretation?

Tags:

matlab

I would like some parameter values to appear where the white box is in my picture (subplot(3,2,1)). It would be ideal if the interpretation in title() could be latex, like the others.

I have tried the following:

title( sprintf( ' $\delta$ = %s  $\rho$ = %s  $\xi$ = %s  m =  %s', delta, rho, xi, m), 'Interpreter', 'latex') 

But I get the following error:

Warning: Control Character '\d' is not valid. See 'doc sprintf' for control characters valid in the format string. 
> In SIXY_sol (line 21) 
Warning: Error updating Text.

 String must have valid interpreter syntax:
 $

How can I fix this?

enter image description here

like image 520
user3600497 Avatar asked Jul 20 '15 05:07

user3600497


1 Answers

This is not a problem with using the LaTeX interpreter but rather with the way you have used sprintf. In the docs for sprintf, scroll down to the section Text Before or After Formatting Operators. Here you will see that the \ character is used to begin an escape sequence so that you can do things like \n for a new line. You actually want \ to appear in your string so you need to escape the escape character. From that table in the docs you need to replace all of your \ with \\.

Try:

title( sprintf( ' $\\delta$ = %s  $\\rho$ = %s  $\\xi$ = %s  m =  %s', delta, rho, xi, m), 'Interpreter', 'latex') 
like image 80
Dan Avatar answered Oct 11 '22 12:10

Dan