简体   繁体   中英

Matlab plot legend include a fraction and a mathematical symbol

I wanted to print a fraction (\frac{W}{m^2}) and mathematical symbol (Deg c) in the legend of the plot in MATLAB.

Tc = [10,20,30]
legend('300 \frac{W}{m^2}, %.f °C',Tc(1));

It is not working. Giving following error

Error using legend (line 261)
Invalid argument. Type 'help legend' for more information.

Error in DifferentSixePVarrays_configurations_IVcurves (line 95)
legend('300, %.f °C',Tc(1),'400','500','600','700','800','900','1000'); % $$\frac{W}{m^2}$$,%.f °C

It has nothing to do with the maths symbols, you are inputting an integer ( Tc(1) ) and that is invalid.

It seems that what you want is to create a string using Tc(1) . You need to do that in a separate step, not as an input to legend . You can do that with either standard string concatenation, ie ['300 ', num2str(Tc(1)), ' °C'] or with sprintf which allows that "C style" string definition (the %f stuff).

On that note, you may need to set the interpreter to Latex, and you may need to add the Latex equivalent to ° for it to work, but this is secondary, not the cause of your error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM