How can I store the places of two different points at two different time?

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Elias Gule
Elias Gule am 29 Mär. 2018
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

Weitere Antworten (1)

Amina
Amina am 29 Mär. 2018
Hello Elias,
Thank you for your time.
It is partly what I am looking for.
Just I would like to re-explain what I mean for 0.01. The points are (x(150),y) at t=150 and (x(200)),y) at t=200, so y values are 0.01 everytime. My position vector will change according to time, so I do not have exact values for them.
Even so, your response was very helpful, thank you again.
  1 Kommentar
Elias Gule
Elias Gule am 29 Mär. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by