Legend in a "for loop"

2 ビュー (過去 30 日間)
Paul Rogers
Paul Rogers 2019 年 11 月 10 日
コメント済み: TADA 2019 年 11 月 11 日
hi,
I need to insert a legend for each ii evalueted.
giri can change in size at every simulation.
for ii=1:length(giri)
figure(3);
plot(m(indice_m_0:loc(ii)),psic_pos(ii,indice_m_0:loc(ii)));
grid on
hold on
end

回答 (1 件)

Shubham Gupta
Shubham Gupta 2019 年 11 月 11 日
Try :
for ii=1:length(giri)
figure(3);
plot(m(indice_m_0:loc(ii)),psic_pos(ii,indice_m_0:loc(ii)),'DisplayName',['ii = ',num2str(ii)]);
grid on
hold on
end
legend show
  5 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 11 日
figure(3);
for ii=1:length(giri)
plot(m(indice_m_0:loc(ii)),psic_pos(ii,indice_m_0:loc(ii)),'DisplayName',sprintf('giri = %g',giri(ii)));
grid on
hold on
end
legend show
Change the %g format to whatever you need.
TADA
TADA 2019 年 11 月 11 日
probably because of an implicit conversion from double to char
maybe this would work:
plot(m(indice_m_0:loc(ii)),psic_pos(ii,indice_m_0:loc(ii)),'DisplayName',['giri = ', num2str(giri(ii))]);
next time it would be better if you attach the data, without sample data helping you is pretty much guesswork...

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

カテゴリ

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