How to show multiple lines in the legend?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The legend shows only one value of EC which is the last one as shown in fig, however my EC has 10 values and I'd lke to display all of them in the legend one-byone in a column. The EC vector and syntax for the lenegd I'm using can be seen
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)
...
lgd=legend(['EC=',num2str(EC(j)),'m^{-1}']);
...
end
0 Kommentare
Antworten (1)
Cris LaPierre
am 12 Apr. 2021
You are replacing the legend each time. Use the loop to build up your labels, but don't atually create the legend until you exit the for loop.
Another option is to use the 'DisplayName' name value pair in your plot command.
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)
plot(rand(1,5),'DisplayName',['EC=',num2str(EC(j)),'m^{-1}']);
hold on
end
hold off
legend
I'm not sure you want to include a lenged label for every line in your plot. I don't see how that will clarify anything.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!