MATLAB: How to animate the plot

animateplot

x=randn(2,10000); a=x(1,:); b=x(2,:); figure;plot(a,b,'.')

Best Answer

x=randn(2,10000);
a=x(1,:);
b=x(2,:);
% figure;
% plot(a,b,'.')
figure(1)
axis([min(a) max(a) min(b) max(b)])
hold on
filename = 'test.gif';
for n = 1:length(a)
plot(a(n),b(n),'.')
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end