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!