Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

matlab - Plot for loop legend with fraction

I am using MATLAB R2018b. I have a for loop plot. I am struggling with legend which has fraction in it.

My code and present 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

image

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

° is not recognizable by Latex and the fraction should be enclosed inside $_____$. You should be using $^circ$ for getting ° with the Latex Interpreter.

i.e. 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*:

image

* Ignore the colors


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...