Question

I have a y matrix that is a 1001x2 and each column represents the phase angle of an oscillator. I'm trying to make a matlab movie so that I plot both phase angles at time t for times, one at a time. So basically it should look like 2 points moving around in circles. If I hold on the plot then it seems to be right, except at all the points are on the frames. But if I dont hold on, then only the second plot gets shown in each iteration (there is only a red * every frame). Any idea whats going on and how I can make both points get shown on each frame?

fig1=figure(1);
winsize = get(fig1,'Position');
winsize(1:2) = [0 0];
numframes=100;
A=moviein(numframes,fig1,winsize);
set(fig1,'NextPlot','replacechildren')
i=1;

%hold on
for frame=1:numframes
i=frame*10;
plot(cos(mod(y(i),2*pi)),sin(mod(y(i),2*pi)),'bo');
plot(cos(mod(y(i,2),2*pi)) *1.1,sin(mod(y(i,2),2*pi))*1.15,'r*'); %only this one is shown
axis([-1.5 1.5 -1.5 1.5])
A(:,i)=getframe(fig1,winsize);
end 
Was it helpful?

Solution

well, you can hold on during the frame drawing and hold off at the end of the frame drawing. like

 for frame=1:numframes
 i=frame*10;

 plot(cos(mod(y(i),2*pi)),sin(mod(y(i),2*pi)),'bo');   
 hold on   % // here
 plot(cos(mod(y(i,2),2*pi)) *1.1,sin(mod(y(i,2),2*pi))*1.15,'r*');
 axis([-1.5 1.5 -1.5 1.5])
 A(:,i)=getframe(fig1,winsize);
 hold off  % // and here
 end 

but in this case you can simply do

 ....
 plot(cos(mod(y(i),2*pi)),sin(mod(y(i),2*pi)),'bo', ... 
     cos(mod(y(i,2),2*pi)) *1.1,sin(mod(y(i,2),2*pi))*1.15,'r*');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top