Produce a legend in for loop that takes entries from an array
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Merry Christmas to all of you. I am trying to incorporate a legend in for loop. my code is the following:
s=['T '; 'Pb '; 'Pf '; 'Pc '; 'Psh '; 'Pito'];
t=cellstr(s);
figure
for k=1:length(pl(end,end,:))
for m=1:length(pl(:,end,end))
subplot(2,3,m) % BUSBAR
semilogx(dim(1,Nmin:Nmax,k)*1000,pl(m,Nmin:Nmax,k),'linewidth',2)
title(t(k))
hold all
end
end
My idea is simple. I want to have a legend that takes values from an array. So if for example I have six curves per plot, I would like to have one legend with 6 entries. I would like something like that because I change very frequently the number of entries and the entries themselves. To give you more details I would like to build a legend with 4 entries and each entry I would like to say 1cm 2cm 3cm 4cm. But I might change that later to 6 different entries.
For that reason I am trying to use a function from the matlab file exchange legend1.m. You can find this in: http://www.mathworks.in/matlabcentral/fileexchange/39505-legend1-m.
I didn't have any success yet. Can you help me please.
0 comentarios
Respuesta aceptada
Matt J
el 25 de Dic. de 2012
Editada: Matt J
el 25 de Dic. de 2012
My idea is simple. I want to have a legend that takes values from an array.
That doesn't require any special files. Here's a simplified example,
l={'a','b','c'};
figure
plot(1:5,1:5,1:5,1:5);
legend(l{[2,3]});
figure
plot(1:5,1:5,1:5,1:5);
legend(l{[1,3]});
2 comentarios
Matt J
el 25 de Dic. de 2012
Editada: Matt J
el 25 de Dic. de 2012
Giorgos commented:
Thank you. Indeed that is much more simple and efficient. On the other hand what if I want to have a constant character cell in all my legend entries and that is cm and add to it the number from an array and this array would be
l=[1 2 3 4]
so the output in the legend would be:
- 1 cm
- 2 cm
- 3 cm
- 4 cm
Más respuestas (2)
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!