我希望在MATLAB中有一个圆形的2个移动点。我有以下脚本:
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
脚本有效,但它只移动一个点而不是点。有人可以帮助我,并说为什么只有一点移动?
亲切的问候
答案 0 :(得分:0)
第一个猜测是你可能想要这个:
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)