フィルターのクリア

Color of legend does't change in the loop.

4 ビュー (過去 30 日間)
Sa Moha
Sa Moha 2021 年 12 月 10 日
回答済み: Rik 2021 年 12 月 10 日
Hi guys
Please run this simple code:
syms x z;
for i=1:2
z=[x,0];
fplot(z(1,1),[i i+1] , 'r');
title('z(x)');
hold on;
end
for j=1:2
z=[-x,0];
fplot(z(1,1),[j j+1] , 'b');
title('z(x)');
legend('one' , 'two');
hold on;
end
Why the legend color is red for 'two' ?
I defined blue for it. Can someone help here please?
Thank you.
  1 件のコメント
KSSV
KSSV 2021 年 12 月 10 日
It is because, the first loop plots in red color.

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

採用された回答

Rik
Rik 2021 年 12 月 10 日
Each call to fplot will create a line object. So in your code you create 4 objects, but you provide only 2 legend entries.
syms x z;
plot_handles=[];
for i=1:2
z=[x,0];
plot_handles(i)=fplot(z(1,1),[i i+1] , 'r');
hold on;
end
for j=1:2
z=[-x,0];
plot_handles(i+j)=fplot(z(1,1),[j j+1] , 'b');
hold on;
end
title('z(x)');
legend(plot_handles([1 3]),{'one' , 'two'});

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by