i have a question regarding legend for movies. This is my code:
fig = figure();
for i = 1: 70000
plot(signal1)
hold on;
plot([i,i],[-5,5])
plot(signal2,'r')
hold off;
title('\fontsize{14} my data');
legend('signal1','signal2');
axis tight;
f(i) = getframe(fig);
end
The legend shows the same colors for the first two things I plot. if I plot more it works for the other plots. Is there a trick I don't know?
The strings defined in the
legend
command are assigned in order of the plots being generated. This means that your first string'signal1'
is assigned to the plot forsignal1
and the second string'signal2'
is assigned to the vertical line.You have two possibilities to fix this problem.
plot
for the vertical line after the plot for the two signals.Here is an example of changing the order:
Here is an example that uses handles (
sp1
andsp2
):