Iterative legend for multple curves on the same plot

10 ビュー (過去 30 日間)
Fabio
Fabio 2014 年 5 月 31 日
回答済み: Thomas 2014 年 10 月 1 日
Hi
I have a 96xn matrix A where number of rows represent the quarters (of an hour) in a day.
I plot it in this way plot(x,A) where x=0.25:0.25:24.
How can I make an iterative legend? I would like to have a legend as curve 1, curve 2, ...... curve n and when n is very high it is very boring.
Thank you

採用された回答

Sara
Sara 2014 年 5 月 31 日
you can do:
txt = cell(n,1);
for i = 1:n
txt{i}= sprintf('curve %i',i);
end
legend(txt)

その他の回答 (1 件)

Thomas
Thomas 2014 年 10 月 1 日
...and here is the trick to do it in one line:
legend(cellstr(int2str([17:28]')))
will just display the numbers in the array [17:28] in this case 17, 18, 19,... (The order of dimensions of [17:28] matters! Therefore in this case [17:28]' is used.

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by