0
votes

I want to have 2 moving points along a circle in MATLAB. I have the following script:

xCenter = 5;
yCenter = 5;
theta = 0 : 0.01 : 2*pi;
radius = 8;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;

figure
plot(x,y);
hold on; % hold on so that the figure is not cleared
hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ...  
    'Marker','o', 'MarkerSize',6, 'LineWidth',2);  
hLine2 = line('XData',x(1), 'YData',y(1), 'Color','g', ...  
    'Marker','o', 'MarkerSize',6, 'LineWidth',2); 


for i=1:length(x)
 set(hLine,'xdata',x(i),'ydata',y(i)); % move the point using set
                                  % to change the cooridinates.
 M(i)=getframe(gcf);

end


for j=1:length(x)

 set(hLine2,'xdata',x(j),'ydata',y(j)); % move the point using set
                                  % to change the cooridinates.
 N(j)=getframe(gcf);

end



%% Play the movie back


% create figure and axes for playback
figure
hh=axes;
set(hh,'units','normalized','pos',[0 0 1 1]); 
axis off

movie(M)
movie(N)% play the movie created in the first part

The script works but it moves only one point and not the the points. Can somebody help me and say why only one point moves?

Kind Regards

1
Please explain what your problem is. It's great to post your code, but you should also explain exactly where you are struggling rather than expect people to analyse your code line by line looking for a problem - Dan
Sorry i pressed to fast on submitting. I hope you now understand it. - skfjsdlfk

1 Answers

0
votes

A first guess is maybe you wanted this:

for ii=1:length(x)
   set(hLine,'xdata',x(ii),'ydata',y(ii)); 
   set(hLine2,'xdata',x(length(x) - ii + 1),'ydata',y(length(x) - ii + 1));                              
   M(i)=getframe(gcf);
end
.
.
.
movie(M)