'legend' problem
Mostra commenti meno recenti
Hello,
I'm using hold on to draw different vectors on the same graph but every time I add a curve I need to add its legend. My problem is that when I write 'legend('Curve Name')' it appears only the last and I'd need to see all the names together$ on the same legend.
Thank you very much
Silvia
1 Commento
Silvia
il 5 Gen 2012
Risposta accettata
Più risposte (2)
Matt Tearle
il 5 Gen 2012
As Junaid says, plotting all together is the nicest solution. However, if, for some reason, that isn't feasible for you, you can do this to recover the strings used so far and add a new one:
h = legend('Curve name 1');
for k = 1:n
% add plot
h = legend([get(h,'String'),'Curve name k']);
end
1 Commento
Silvia
il 9 Gen 2012
Patrick Kalita
il 5 Gen 2012
This is along the same lines as Junaid's answer. The idea is to use the plot's DisplayName property to set the legend text for each curve. A combination of legend off and legend show will cause the legend to be repopulated with any new plots that have been added. For example:
hold all
for i = 1 : 10
plot( rand(1, 50), 'DisplayName', sprintf( 'Plot #%d', i ) );
legend off; legend show;
pause(0.5);
end
hold off
1 Commento
Silvia
il 9 Gen 2012
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!