Use Legend to show array and matrix
Show older comments
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
Accepted Answer
More Answers (1)
Honglei Chen
on 16 Dec 2013
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 Comments
Wei
on 16 Dec 2013
Azzi Abdelmalek
on 16 Dec 2013
Why have you changed your question?
Wei
on 16 Dec 2013
Honglei Chen
on 16 Dec 2013
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
on 16 Dec 2013
Honglei Chen
on 17 Dec 2013
You change the second one to a regular array, you can use Walter's code below
Wei
on 17 Dec 2013
Wei
on 17 Dec 2013
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!