how can I show all of my data in the legend for each curve?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
My plot has 10 curves which are according to the data of EC as shown in figure. However the legend displays only the last term in EC, where EC is a row vector as shown. I want to display all the data terms in EC in the legend one by one to exactly express the plotting curves. My syntax for the legend is given by:
EC = [0.0052 0.0078 0.0104 0.0130 0.0156 0.0182 0.0208 0.0234 0.0260 0.0286];
for j = 1:length(EC)
.
.
.
end
lgd=legend(['EC=',num2str(EC(j)),'\m'])
0 comentarios
Respuestas (2)
Christopher McCausland
el 20 de Mzo. de 2021
lgd is outside the for loop with no buffer array to hold the data. This is why only the last value is being displayed. While this would work if the position of lgd was changed to inside the for loop any inclusion of a for loop with the plot command makes me a little nervous due to the computational resorces required.
I would suggest trying something like this instead: (note the changes to 'legend')
EC = [0.0052 0.0078 0.0104 0.0130 0.0156 0.0182 0.0208 0.0234 0.0260 0.0286];
legend(['EC=',num2str(EC),'\m']);
There may need to be some additional formatting however that should display everything. Let the forumm know how it goes and if you need any other help with it.
Christopher
0 comentarios
darova
el 20 de Mzo. de 2021
Try this
[x,y] = meshgrid(0:0.1:5,0:5);
y = sin(x)./y;
plot(x',y')
s0 = sprintf('curve #%d,',0:5);
s1 = strsplit(s0,',');
legend(s1{1:end-1})
3 comentarios
Ver también
Categorías
Más información sobre Title 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!