Automatically assign legend name to set of data

4 visualizaciones (últimos 30 días)
fede
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...???

Respuesta aceptada

Mathieu NOE
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
fede
fede el 5 de Abr. de 2023
sure, did it work?

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by