Use Legend to show array and matrix
2 views (last 30 days)
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
0 Comments
Accepted Answer
Walter Roberson
on 17 Dec 2013
legend( arrayfun(@(K) sprintf('%s=%d',A{K}, B(K)), 1:length(A), 'UniformOutput', false) )
4 Comments
Walter Roberson
on 17 Dec 2013
You can only have one legend entry per plotted item (e.g., one per line).
How are you doing your plotting, and what are the size() of the matrices you are plotting ?
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
See Also
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!