MATLAB Answers

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

15 views (last 30 days)
AKHILESH  BARNWAL
AKHILESH BARNWAL on 21 Jan 2020 at 13:35
Commented: AKHILESH BARNWAL on 28 Jan 2020 at 11:40
% 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

  0 Comments

Sign in to comment.

Accepted Answer

Cameron B
Cameron B on 21 Jan 2020 at 13:51
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 Comment

AKHILESH  BARNWAL
AKHILESH BARNWAL on 28 Jan 2020 at 11:40
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.

Sign in to comment.

More Answers (0)

Sign in to answer this question.