
Automatically assign legend name to set of data
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello,
I have to plot different curves in a single graph. The number of the curves to plot can change. I would like to automatically rename the various curves by replacing the default name data1, data2, ecc...
Is there a simple way to do this?
I attach a simplified version of my code.
Thank you very much for your help
n=input('Enter the number of curves you want to fit: ');
m=10;
x=zeros(m,1);
y=zeros(m,n);
x(:,1)=1:1:m;
for k=1:n
for j=1:m
y(j,k)=k+j;
end
end
figure()
semilogx(x(:,1),y(:,:),"o")
legend()
%how to rename y(:,1), y(:,2) etc... with y1, y2, ecc...???
댓글 수: 0
채택된 답변
Mathieu NOE
2023년 4월 5일
hello
maybe this ?
now you have y1,y2,... in your legend

n=input('Enter the number of curves you want to fit: ');
m=10;
x=zeros(m,1);
y=zeros(m,n);
x(:,1)=1:1:m;
for k=1:n
for j=1:m
y(j,k)=k+j;
end
leg_str{k} = ['y' num2str(k)];
end
figure()
semilogx(x(:,1),y(:,:),"o")
legend(leg_str)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!