MATLAB: How to fix legend in an animate plot 2D

animateplot

figure(1)
for j = 1:length(t)
plot(x,u(:,j),x,v(j,:),x,LF(j,:))
pause(0.1)
end
I would see the legend also the animate is running. Not only at the end of this. Thanks all.

Best Answer

clc; clear all ;
x = linspace(-2*pi,2*pi);
y1 = sin(x);
y2 = cos(x);
for i = 1:100
plot(x,rand(1)*y1,'r',x,rand(1)*y2,'b')
legend('sin(x)','cos(x)')
pause(0.1)
drawnow
end