How to change legends' name
71 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lydia Abigail Garza Coello
le 19 Mai 2021
Modifié(e) : the cyclist
le 19 Mai 2021
Hi,
I have a code for plotting different curves that appears as time increases. The number of curves that are displayed depends on the input data each time I run the program, so I could have 6, 8, 10, etc., curves (unknown). My problem is that I want to label each of the curves as "Theta n" (n is 1,2,3,4....) but I don´t know how to include that in the legend command. The graph is like the following image:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/622063/image.png)
Thanks,
Abby
0 commentaires
Réponse acceptée
the cyclist
le 19 Mai 2021
Modifié(e) : the cyclist
le 19 Mai 2021
Here is a basic way you can do it:
N = 3;
figure
hold on
for ii = 1:N
plot(rand(1,7),'DisplayName',sprintf('Theta %d',ii))
end
legend()
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!