[英]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.我想在 MATLAB 的 plot 的图例中打印一个分数 (\frac{W}{m^2}) 和数学符号 (Deg c)。
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.它与数学符号无关,您输入的是 integer (
Tc(1)
),这是无效的。
It seems that what you want is to create a string using Tc(1)
.看来您想要的是使用
Tc(1)
创建一个字符串。 You need to do that in a separate step, not as an input to legend
.您需要在单独的步骤中执行此操作,而不是作为
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).您可以使用标准字符串连接来做到这一点,即
['300 ', num2str(Tc(1)), ' °C']
或使用允许“C 风格”字符串定义的sprintf
( %f
东西)。
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.关于这一点,您可能需要将解释器设置为 Latex,并且您可能需要添加与
°
等效的 Latex 才能使其工作,但这是次要的,而不是导致错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.