Automatically assign legend name to set of data

조회 수: 4 (최근 30일)
fede
fede 2023년 4월 5일
댓글: Mathieu NOE 2023년 4월 5일
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...???

채택된 답변

Mathieu NOE
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)
  댓글 수: 4
fede
fede 2023년 4월 5일
sure, did it work?
Mathieu NOE
Mathieu NOE 2023년 4월 5일
yeap
tx

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by