Hold all the legends while plotting multiple figures inside a for loop
조회 수: 3 (최근 30일)
이전 댓글 표시
A sample code is given below. Only the last legend entry is appearing in the plot. My attempt is to display all the legend entries in the plot. Hold all is not holding the legends but only coloring the plots.
clc
clear all
freq=20:20:100;
accln=[1 1 1 1 1;2 2 2 2 2;3 3 3 3 3;4 4 4 4 4;5 5 5 5 5];
data=[freq' accln'];
rms=zeros(5,1);
for i=1:5
rms(i)=sqrt(sum(data(:,i+1)));
end
for m=1:1:5
plot(data(:,1),data(:,m+1),'LineWidth',2)
hold all
ylim([0 6])
xlabel('Freq','FontSize',12)
ylabel('Accleration','FontSize',12)
set(gca,'FontSize',12)
leg=legend([num2str(m),'-',num2str(m+1),'s',' ',num2str(rms(m),'%.1f'),' ','grms']);
set(leg,'Location','SouthEast')
grid on
orient landscape
end
print('-dpdf','Hold legend.pdf','-r0');
댓글 수: 0
채택된 답변
KSSV
2018년 11월 9일
편집: KSSV
2018년 11월 9일
clc
clear all
freq=20:20:100;
accln=[1 1 1 1 1;2 2 2 2 2;3 3 3 3 3;4 4 4 4 4;5 5 5 5 5];
data=[freq' accln'];
rms=zeros(5,1);
for i=1:5
rms(i)=sqrt(sum(data(:,i+1)));
end
leg = cell(5,1) ;
for m=1:1:5
plot(data(:,1),data(:,m+1),'LineWidth',2)
hold all
ylim([0 6])
xlabel('Freq','FontSize',12)
ylabel('Accleration','FontSize',12)
set(gca,'FontSize',12)
leg{m}=[num2str(m),'-',num2str(m+1),'s',' ',num2str(rms(m),'%.1f'),' ','grms'];
% set(leg{m},'Location','SouthEast')
grid on
orient landscape
end
leg = legend(leg) ;
set(leg,'Location','SouthEast')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Power Converters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!