필터 지우기
필터 지우기

How can I make an animating plot moving with the speed I predefined?

조회 수: 1 (최근 30일)
Jiwoo
Jiwoo 2023년 7월 19일
댓글: Jiwoo 2023년 7월 21일
Hello, I am trying to make a simple simulation of a robot following straight lines. I am using a plot function and I would like to know how to make the robot in the plot move with the speed I want (ex. 2 m/s or 5 m/s)
Thank you!
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 7월 19일
One way would be to update the coordinates of the robot according to the velocity after each iteraion.

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

채택된 답변

Benjamin Kraus
Benjamin Kraus 2023년 7월 19일
This is a very basic/crude example, but it shows some basic concepts:
y0 = 0; % Starting location
v0 = 100; % Starting velocity
a = -10; % Acceleration
p = plot(0, y0, 'o');
xlim([0 25])
ylim([0 600])
drawnow
t0 = datetime(); % Get the starting time.
tnow = t0;
while (tnow - t0 < minutes(1) && p.YData >= 0)
t = seconds(tnow-t0); % How much time has passed?
p.XData = t;
p.YData = y0 + v0*t + 0.5*a*t.^2;
drawnow
tnow = datetime(); % Get the current time
end
  댓글 수: 2
Benjamin Kraus
Benjamin Kraus 2023년 7월 19일
Once you get that working, you may want to look into either timer or backgroundPool so you can run the simulation without blocking the MATLAB command window (for example Background Processing).
Jiwoo
Jiwoo 2023년 7월 21일
Thank you for your clear explanation!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by