Sunday 15 June 2014

Matlab animation loop -



Matlab animation loop -

i have next loop produce animation:

for ii=1:5:length(coors)-5 jj=1:6 plot(coors(ii,1),coors(ii,2),'o','color',cc(ii,:),'markersize',jj) plot(coors(ii+1,1),coors(ii+1,2),'o','color',cc(ii+1,:),'markersize',jj) plot(coors(ii+2,1),coors(ii+2,2),'o','color',cc(ii+2,:),'markersize',jj) plot(coors(ii+3,1),coors(ii+3,2),'o','color',cc(ii+3,:),'markersize',jj) plot(coors(ii+4,1),coors(ii+4,2),'o','color',cc(ii+4,:),'markersize',jj) drawnow frame = getframe; writevideo(writerobj,frame); end end

this plots batch of 5 points (ii in steps of 5) simultaneously marking them growing circles (jj 1 6) , works well.

what want have whole thing growing 1 point @ time, 1 size time until reach dessired size, is:

frame one: point 1->size 1

frame two: point 1->size 2, point 2->size 1

...

frame five: point 1->size 5, point 2->size 4, point 3-> size 3 ...

frame six: point 6->size 1, point 2->size 5,...

can think of elegant way without many many loops , ifs?

here comes simplified solutions draws 6 points , stores plot handle each point. handles used adjust markersize of points 1 in each iteration. can adapt code case.

coors = rand(6,2); % random coordinates figure axis([0, 1, 0, 1]) hold on handles = []; % vector store plot handles in ii=1:6 handle = plot(coors(ii,1),coors(ii,2),'ko','markerfacecolor', 'black', 'markersize',1); % adjust handles h = 1:length(handles) set(handles(h), 'markersize', get(handles(h), 'markersize') + 1); % increment markersize 1 end % add together new handle handles vector handles = [handles, handle]; % draw pause(1) end

reading markersize property in end yields desired markersizes

get(handles, 'markersize') ans = [6] [5] [4] [3] [2] [1]

matlab loops animation

No comments:

Post a Comment