how to add a new entry for legend while running a multiple plot

7 ビュー (過去 30 日間)
AKHILESH BARNWAL
AKHILESH BARNWAL 2020 年 1 月 21 日
コメント済み: AKHILESH BARNWAL 2020 年 1 月 28 日
% Timeseries Simulation
clear all;
clc
tic
x=1:10;
Sol=zeros(Nhr,6);
for i=1:3
y=i.*x;
figure (1), fig1 = plot(x,y);
legend(['plot for run ',num2str(i)])
hold on
end

回答 (1 件)

Cameron B
Cameron B 2020 年 1 月 21 日
x=1:10;
hold on
for ii=1:3
y=ii.*x;
fig1 = plot(x,y);
legvec{ii} = sprintf('plot for run %d',ii);
end
legend(legvec,'Location','northwest')
hold off
  1 件のコメント
AKHILESH BARNWAL
AKHILESH BARNWAL 2020 年 1 月 28 日
Thanks for the Answer.
This solution is quite good as I wanted, but there is no significance of this code as this code for legend entry does not recognize the plot of its own legend.,because all the legend entry are marked in same colour so it is difficult to identify the relevant plot with corresponding entry in legend. Please update me.
Thanks again for help.

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

カテゴリ

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