Use Legend to show array and matrix
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Honglei Chen
am 16 Dez. 2013
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 Kommentare
Wei
am 16 Dez. 2013
Azzi Abdelmalek
am 16 Dez. 2013
Why have you changed your question?
Wei
am 16 Dez. 2013
Honglei Chen
am 16 Dez. 2013
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
am 16 Dez. 2013
Honglei Chen
am 17 Dez. 2013
You change the second one to a regular array, you can use Walter's code below
Wei
am 17 Dez. 2013
Wei
am 17 Dez. 2013
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!