How to write a short syntax for the legend?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The legend in the plot shows seven lines is according to the length of EC in the program. I want to write one syntax for the legend in terms of the index i instead of seven, so that it repeats for the values of EC and gives me the same figure
clc
clear all
%------------------------------Program-------------------------------------
EC = [0.0052 0.0078 0.0104 0.013 0.0156 0.0182 0.0208];
Reff = 7;%if we write Ref=4:1:20 then all the effective radii from 1 to 20 will be executed at once and will gives 20 figures, otherwise writing only one will execute only one
h=2115:9:2394;
for j = 1:length(Reff)
hold on
for i = 1:length(EC)
filename1 = [num2str(EC(i)),'\',num2str(Reff(j)),'um\out_resultsG_I0.dat'];
I1 = getsignal(filename1);
I1(isnan(I1))=0;
I0_1 = sum(I1,2);
filename1 = [num2str(EC(i)),'\',num2str(Reff(j)),'um\out_resultsG_Q0.dat'];
Q1 = getsignal(filename1);
Q1(isnan(Q1))=0;
Q0_1 = sum(Q1,2);
dep(:,j)=(I0_1-Q0_1)./(I0_1+Q0_1);
plot(dep,h,'LineWidth',2);
end
end
%--------------------------------------------------------------------------
hold off
%-----------------------------Title----------------------------------------
title(['Effective radius=',num2str(Reff(j)),'\mum',', FOV=2mrad'],'FontSize',12,'FontWeight','normal');
xlabel('Depolarisation ratio \delta_{out}','FontSize',12,'FontWeight','normal');
ylabel('Cloud depth (m)','FontSize',12,'FontWeight','normal');
%------------------------------Legend--------------------------------------
legend(['EC=',num2str(EC(1)),'/m'],['EC=',num2str(EC(2)),'/m'],['EC=',num2str(EC(3)),'/m'],...
['EC=',num2str(EC(4)),'/m'],['EC=',num2str(EC(5)),'/m'],['EC=',num2str(EC(6)),'/m'],...
['EC=',num2str(EC(7)),'/m'],'location','Southeast')
.
0 commentaires
Réponses (1)
Steven Lord
le 4 Mar 2021
Set the DisplayName property of each line just like you set the LineWidth. Then legend show will make the legend appear and use the DisplayName property values.
x = 0:360;
axis([0 360 -1 1])
hold on
plot(x, sind(x), 'ro-', 'MarkerIndices', 1:60:numel(x), 'DisplayName', 'sine')
plot(x, cosd(x), 'k^:', 'MarkerIndices', 30:60:numel(x), 'DisplayName', 'cosine')
legend show
I used MarkerIndices too because I didn't want the plots to be covered with their markers.
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!