Moving and stopping simulation code?

조회 수: 3 (최근 30일)
Rudi Gunawan
Rudi Gunawan 2016년 6월 22일
댓글: KSSV 2016년 6월 22일
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.

채택된 답변

KSSV
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
Rudi Gunawan
Rudi Gunawan 2016년 6월 22일
편집: Rudi Gunawan 2016년 6월 22일
I got some problem with the if condition, it say "The expression to the left of the equals sign is not a valid target for an assignment." What should I do with this kind of problem? I have tried using 2 equal sign (==), it work but didn't stop the movement. What should I do?
KSSV
KSSV 2016년 6월 22일
you have to read document....for if..you cannot expect each and every minor help online...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by