How can I store the places of two different points at two different time?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have to measure a distance between two points. I have to see where the solution across some values quite small, like 0.01. In other words, there should be the first point which is like (x(150), 0.01) at t=150 and the second one should be (x(200), 0.01) at t=200. Distance should be equal (x(200)-x(150)) because y-values are the same.
My problem is that how can I store/ calculate the x(150) and x(200) places when the time reaches to t=150 and t=200, respectively?
I will be very glad if someone can answer my question.
Many thanks in advance.
댓글 수: 0
채택된 답변
Elias Gule
2018년 3월 29일
I think this is what you mean: You have a time vector with elements like 150,200,etc,
and a position vector with elements like 0.01,0.01,etc.
If this is true, then I guess the code you that you want is:
t = [150 200 300 400 500]; % replace with your own time vector
x = [0.01 0.01 1 2 5]; % replace with your own position/x vector
t0 = 150; % time for point 1
t1 = 300; % time for point 2
x0 = x(ismember(t,t0));
x1 = x(ismember(t,t1));
dx= x1 - x0; % delta x
dy = 0; % since you said the y-values are always the same
dist = hypot(dx,dy); % the distace between two points
댓글 수: 0
추가 답변 (1개)
Amina
2018년 3월 29일
댓글 수: 1
Elias Gule
2018년 3월 29일
That should not be a problem; because as long as you know the time at which you want a corresponding x-value, the code that I supplied simply applies logical indexing to map that particular time instance to a corresponding position.
let's say for example, that, at t= 1507, the x-value is 1663, the code will be able to map these two values, as long as the t-vector and the x-vector has the same length.
The assumption that I'm making here is that the elements in the t- and x-vectors are mapped position-wise.
Thanks.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!