2013-10-18 61 views
0

我想在MATLAB中沿着一個圓有2個運動點。我有以下腳本:沿着圓創建2個運動點MATLAB

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 

該腳本的作品,但它只移動一個點,而不是點。有人能幫助我說出爲什麼只有一點動作?

親切的問候

+1

請解釋一下你的問題是什麼。發佈代碼非常好,但是你也應該解釋你在哪裏掙扎,而不是期望人們逐行分析你的代碼來尋找問題 – Dan

+0

抱歉,我按下了快速提交。我希望你現在瞭解它。 – skfjsdlfk

回答

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) 
+0

現在它只移動一個點,因爲變量i只在for循環中。 – skfjsdlfk

+0

@skfjsdlfk對不起,'j's應該是'我'。另外還有一個附註,'i'(和'j')是Matlab中sqrt(-1)的一個常量,所以經常建議不要將它用作matlab中的變量名稱。 – Dan

+0

Ok tnx關於i和學家但我希望這兩點能夠獨立移動,並且他們甚至需要在特定時間停止特定時間:p – skfjsdlfk