Moving and stopping simulation code?
3 ビュー (過去 30 日間)
古いコメントを表示
Hey guys, I want to simulate a simple moving and stopping simulation. A circle with move along a rectangular path, and then will stop for couple second in some determined spot, and finish after reach the starting point. Can you help me with the code? Thank you in advance.
0 件のコメント
採用された回答
KSSV
2016 年 6 月 22 日
clc; clear all ;
N = 20 ;
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
[X,Y] = meshgrid(x,y) ;
% pick boundaries
x = [X(1,:)' ; X(:,end) ; flipud(X(end,:)') ;flipud(X(:,1))] ;
y = [Y(1,:)' ; Y(:,end) ; flipud(Y(end,:)') ;flipud(Y(:,1))] ;
% x(end) = [] ;y(end) = [] ;
% circle
th = linspace(0,2*pi) ;
r = 0.1 ;
for i = 1:length(x)
xc = x(i)+r*cos(th) ;
yc = y(i)+r*sin(th) ;
plot(x,y,'.-r') ;
hold on
plot(xc,yc,'b');
hold off
% if condition % put your condition to stop the circle
pause(0.1)
% end
end
3 件のコメント
KSSV
2016 年 6 月 22 日
you have to read document....for if..you cannot expect each and every minor help online...
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!