legends after each iteration

1 view (last 30 days)
Kareem AlBokhari
Kareem AlBokhari on 28 Sep 2015
Answered: Walter Roberson on 28 Sep 2015
want to add legends after each iteration in a for loop ?
any suggestions ??
  1 Comment
the cyclist
the cyclist on 28 Sep 2015
This is not twitter. Can you please write out a more complete explanation of what you want? How you have written this, there is too much guesswork for us.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 28 Sep 2015
legend_strings = {};
for K = 1 : 20
h(K) = plot(rand(1,10)); %produce the plot to be legend'd and save the handle
hold on
legend_strings{K} = sprintf('Run #%d', K); %construct the string that is the legend
legend(h(1:K), legend_strings(1:K)); %update the legends
drawnow(); %make the change visible
end

Community Treasure Hunt

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

Start Hunting!