How can I store the places of two different points at two different time?
1 view (last 30 days)
Show older comments
Commented: Elias Gule on 29 Mar 2018
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.
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
More Answers (1)
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.
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!