How to calculate distance left in a specific time interval

조회 수: 1 (최근 30일)
Shin
Shin 2023년 1월 18일
답변: KSSV 2023년 1월 18일
Hi there, I have a start position, start = [1,2]; and an end position, endpos = [8,8];. How can I calculate the distance left to travel for each time interval, for example each time travel, the distance will decrease a little, given that the time array, tVec = 0:interval:100, where interval = 0.1, and velocity, vel = 0.1. Thanks.
start = [1 2];
endpos = [8 8];
interval = 0.1;
vel = 0.1;
tVec = 1:interval:100
-Chann-
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 1월 18일
What are the (x and y) components of the velocity? You have only stated a magnitude.

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

답변 (1개)

KSSV
KSSV 2023년 1월 18일
start = [1 2];
endpos = [8 8];
x = [start(1) endpos(1)]' ;
y = [start(2) endpos(2)]' ;
interval = 0.1;
vel = 0.1;
tVec = 1:interval:100 ;
p = polyfit(x,y,1) ;
xi = linspace(x(1),x(2),length(tVec)) ;
yi = polyval(p,xi) ;
plot(x,y,'*r',xi,yi,'b')

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by