Use Legend to show array and matrix
Afficher commentaires plus anciens
I have one array and one matrix like A={'x' 'y' 'z'}; B=[1 2 3]. I want to make a legend as: x=1 y=2 z=3
in my plot, could anyone help me with this issue.
Thanks
Réponse acceptée
Plus de réponses (1)
Honglei Chen
le 16 Déc 2013
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 commentaires
Wei
le 16 Déc 2013
Azzi Abdelmalek
le 16 Déc 2013
Why have you changed your question?
Wei
le 16 Déc 2013
Honglei Chen
le 16 Déc 2013
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
le 16 Déc 2013
Honglei Chen
le 17 Déc 2013
You change the second one to a regular array, you can use Walter's code below
Wei
le 17 Déc 2013
Wei
le 17 Déc 2013
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!