[英]Plot for loop legend with fraction
I am using MATLAB R2018b.我正在使用 MATLAB R2018b。 I have a for
loop plot.我有一个for
循环 plot。 I am struggling with legend
which has fraction in it.我正在与其中有分数的legend
作斗争。
My code and present output:我的代码和当前 output:
% Plot
ColorVec = hsv(length(Phi));
markers = {'+','o','*','.','x','s','d','^','v','>','<','p','h'};
figure;
set(gca,'fontsize',24,'fontname','Times New Roman');
hold on;
for k = 1:length(Nse)
for i=1:length(Iph)
plot(V11(:),P(:),'-','color',ColorVec(i,:),'Linewidth',2.0);
end
end
%%% Following for legend
Legend = cell(length(Phi),1);
for iter=1:length(Phi)
Legend{iter}=strcat(num2str(Phi(iter)),'\frac{W}{m^2},',num2str(round(Tc(iter))),' °C ');
end
hl = legend(Legend);
set(hl ,'Interpreter','latex')
hold off
°
is not recognizable by Latex and the fraction should be enclosed inside $_____$
. °
无法被 Latex 识别,分数应包含在$_____$
内。 You should be using $^\circ$
for getting °
with the Latex Interpreter.您应该使用$^\circ$
通过 Latex 解释器获取°
。
ie instead of what you have in your loop, you should be having:即,而不是你在你的循环中,你应该有:
Legend{iter}=strcat(num2str(Phi(iter)),'$\frac{W}{m^2}$,',...
num2str(round(Tc(iter))),'$^\circ$C');
or even simpler with the power of strings (instead of characters):甚至更简单的字符串(而不是字符)的力量:
Legend{iter} = Phi(iter) + "$\frac{W}{m^2}$," + round(Tc(iter)) + "$^\circ$C";
Result*:结果*:
* Ignore the colors *忽略 colors
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.