t=0:0.1:2*pi; y=sin(t); y2=cos(t);
h=cell(1);k=1;
h{1}=plot(t(k),y(k),'o');
hold on
h{2}=plot(t(k),y2(k),'o');
h{3}=plot(t(1:k),y(1:k));
h{4}=plot(t(1:k),y2(1:k));
axis([0 2*pi -1 1]);
xlabel('t');
ylabel('y');
legend('sin(t)','cos(t)');
for k=2:length(t)
set(h{1},'XData',t(k),'YData',y(k));
set(h{2},'XData',t(k),'YData',y2(k));
set(h{3},'XData',t(1:k),'YData',y(1:k));
set(h{4},'XData',t(1:k),'YData',y2(1:k));
drawnow
end
3 Comments
Adam Danz (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/478445-how-to-create-2d-plots#comment_741111
Rik (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/478445-how-to-create-2d-plots#comment_741112
Akarsh Shetty (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/478445-how-to-create-2d-plots#comment_741407
Sign in to comment.