Display axis values Line Legends???

Hello every one, when I plot a matrix e.g x= [ 8 36 36; 8 15 15; 8 25 25; 8 3 3], I would like to display the end value of each row for as a legend for each line on the plot.
I tried with 'num2str(x(1,end)),......' comand which works but off course for larger matrices it would b a headache, Is there any possible short command for the whole Action
Best Regards Ali

 採用された回答

Jan
Jan 2013 年 9 月 9 日
編集済み: Jan 2013 年 9 月 9 日

0 投票

You can use a loop:
[m,n] = size(x);
legendText = cell(1, m);
for k = 1:m
legendText{k} = num2str(x(k, n));
end
[EDITED after comment]
x = rand(10, 5);
h = plot(x);
... Instert code from above here
legend(h, legendText);
See doc legend for more details and examples. Reading the documentation is very useful in Matlab, because this is (still, even with the new layout) the most productive documentation I've seen (except for the one of my hammer).

3 件のコメント

Usman  Ali
Usman Ali 2013 年 9 月 9 日
Good that it works to collect the required numbers but how can I put them as legends into a Plot..
Jan
Jan 2013 年 9 月 9 日
See [EDITED]
Usman  Ali
Usman Ali 2013 年 9 月 25 日
Perfect (y), it works all accordingly...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2013 年 9 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by