Use Legend to show array and matrix
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Honglei Chen
il 16 Dic 2013
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 Commenti
Wei
il 16 Dic 2013
Azzi Abdelmalek
il 16 Dic 2013
Why have you changed your question?
Wei
il 16 Dic 2013
Honglei Chen
il 16 Dic 2013
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
il 16 Dic 2013
Honglei Chen
il 17 Dic 2013
You change the second one to a regular array, you can use Walter's code below
Wei
il 17 Dic 2013
Wei
il 17 Dic 2013
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!