フィルターのクリア

I am trying to plot different curves in gui, but i dont know how to add legend to it.

2 ビュー (過去 30 日間)
Ankit Singh
Ankit Singh 2017 年 3 月 31 日
コメント済み: Rik 2017 年 4 月 5 日
My plots depend on a single variable 's' which i take from the user. I get the plot but am unable to get all the legends for different plots that the user plot for different 's' values. This is the plotting part of the code. where 'i' is a global parameter which increments with each new value of 's'.
p(i)= plot(x,y,'linewidth',2,'Color',clr(i));
hold on
grid on
title('Rotor Voltage Limit for Various Slip values')
xlabel('P');
ylabel('Q');
Legend{i}=strcat('S=', num2str(s));
for l=1:i
legend([p(1:l)],Legend{1:l})
end
  2 件のコメント
Rik
Rik 2017 年 3 月 31 日
My first observation is that you don't need the for-loop. The legend function also works if you just enter an array of handles and a cell array. My second observation is that the curly brackets look wrong, as you will not be supplying a cell array as second parameter. I bet you got an error for l==2 (as for l==1 you were just adding a single element legend).
Ankit Singh
Ankit Singh 2017 年 4 月 1 日
YES! I did get an error for l==2. So what am I supposed to do.

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

採用された回答

Rik
Rik 2017 年 4 月 1 日
Try if this works: replace this
for l=1:i
legend([p(1:l)],Legend{1:l})
end
with this
legend(p(1:i),Legend(1:i))
  18 件のコメント
Ankit Singh
Ankit Singh 2017 年 4 月 4 日
Sir, I got it! Omg, I was increasing the counter when a new s value was being entered by the user, so the counter was starting from 1+1, 2, instead of 1, and thus all the errors. I feel silly now, to have wasted so much of both of our time. Thank you so much for your help sir. :)
Rik
Rik 2017 年 4 月 5 日
You're welcome. It is often these little typos that make for the most inexplicable problems.

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

その他の回答 (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