How to change matlab plot legend automatically

5 ビュー (過去 30 日間)
Mainak
Mainak 2012 年 9 月 13 日
Suppose I have a data emax = [1 2 3];
Now I have data X(length(emax), 1:10) and Y(length(emax), 1:10)
When I plot X and Y, I have 3 lines in this case.
My legend is legend('emax =1', 'emax=2', 'emax =3');
Suppose, for a new set of experimental data, I have,
emax =[10 20 30 40 50] and my X and Y data size is now(1:5,1:10). This time my plot will have 5 lines.
I have to manually change the legend to make it right.
Is there a way to create the correct legend automatically in such a situation?
  1 件のコメント
Mainak
Mainak 2012 年 9 月 13 日
I found the answer(s) to my question in
'http://www.mathworks.com/matlabcentral/answers/12845'

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

採用された回答

Jan
Jan 2012 年 9 月 13 日
What does "automatically" exactly mean? You have to provide at least "emax = ", of course. So all you have to do "manually" is to insert the numbers from 1 to 5, correct?
S = sprintf('emax = %d*', 1:5);
C = regexp(S, '*', 'split');
legend(C{:})

その他の回答 (0 件)

カテゴリ

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