Use Legend to show array and matrix
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Honglei Chen
2013-12-16
You can do this:
plot(rand(10,3))
legend(cellfun(@(x,y)sprintf('%s=%s',x,y),A,B,'UniformOutput',false))
8 个评论
Wei
2013-12-16
Azzi Abdelmalek
2013-12-16
Why have you changed your question?
Wei
2013-12-16
Honglei Chen
2013-12-16
Your B now contains numbers, replace the second %s in my code to %d if they are integers
Wei
2013-12-16
Honglei Chen
2013-12-17
You change the second one to a regular array, you can use Walter's code below
Wei
2013-12-17
Wei
2013-12-17
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!