
Automatically assign legend name to set of data
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
fede
el 5 de Abr. de 2023
Comentada: Mathieu NOE
el 5 de Abr. de 2023
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 comentarios
Respuesta aceptada
Mathieu NOE
el 5 de Abr. de 2023
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!