Interpolation x,y from time

44 views (last 30 days)
Montgomery
Montgomery on 10 May 2014
Edited: Montgomery on 10 May 2014
Hi all, I have several variables
time x y
31977674 200 195
31978007 204 198
31978341 200 195
31978674 200 195
31979008 200 195
31979341 201 196
31979674 201 196
31980008 202 196
31980341 202 196
31980674 203 196
......
Presume in this case x,y are positions of say a ball rolling around at a given time. I now have a set of new times without x,y co-ordinates, none of the times match times already existing, so I have gone through the time list and find the two closest to that value (either side.)
So for example: given 31977674 = (200,195) and 31978007 = (204,198) what position am I at with a time 3197900?
I guess I need to use some sort of interpolation function but I'm struggling to see how to apply it in this case. I looked up interp2 in the help:
Vq = interp2(X,Y,V,Xq,Yq) returns interpolated values of a function of two variables at specific query points using linear interpolation. The results always pass through the original sampling of the function. X and Y contain the coordinates of the sample points. V contains the corresponding function values at each sample point. Xq and Yq contain the coordinates of the query points.
But Xq and Yq are the 'co-ordinates of the query points' - I seem to want the opposite of this, I want the points given the time!
Apologies If I have misunderstood, the help is much appreciated.

Accepted Answer

Star Strider
Star Strider on 10 May 2014
Use interp1 and pass both the x and y columns to interpolate both at the same time:
I call your matrix ‘M’ here:
M = [31977674 200 195
31978007 204 198
31978341 200 195
31978674 200 195
31979008 200 195
31979341 201 196
31979674 201 196
31980008 202 196
31980341 202 196
31980674 203 196];
xynew = interp1(M(:,1), M(:,2:3), 31979000)
produces:
xynew =
200 195
The values on either side of it aren’t changing, so it has the same values as its immediate neighbors. (I had a bit of a problem at first because there was a zero missing from your interpolation point.)
For two points between x and y values that are changing, the results are a bit more apparent:
xynew = interp1(M(:,1), M(:,2:3), [31978225; 31979225])
produces:
xynew =
201.3892 196.0419
200.6517 195.6517
  2 Comments
Montgomery
Montgomery on 10 May 2014
Edited: Montgomery on 10 May 2014
Just tested this and it is exactly what I am after, perfect answer. :-) Also thank you for your examples, especially the second one it really cleared everything up.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!