Reputation: 1936
This is probably a very easy question, but all the sources I have found on interpolation in Matlab are trying to correlate two values, all I wanted to benefit from is if I have data which is collected over an 8 hour period, but the time between data points is varying, how do I adjust it such that the time periods are equal and the data remains consistent?
Or to rephrase from the approach I have been trying: I have GPS lat,lon and Unix time for these points; what I want to do is take the lat and lon at time 1 and time 3 and for the case where I don't know time 2, simply fill it with data from time 1 - is there a functional way to do this? (I know in something like Python Pandas you can use fill) but I'm unsure of how to do this in Matlab.
Upvotes: 2
Views: 769
Reputation: 715
There is a MATLAB function called interparc.m which will benefit you. It fits a cubic spline through the points and divides the resulting line into equal arc-lengths (depending on the number of points entered by the user)
Upvotes: 2
Reputation: 3037
You might try something along the lines of this:
resampledTime = min(unixTime):resampleInterval:max(unixTime);
resampledLat = interp1(time,lat,resampledTime);
resampledLon = interp1(time,lon,resampledTime);
By default, this returns 1-dimensional linear interpolation. For more info, see help interp1
Upvotes: 2
Reputation: 114826
I think you are looking for a "zero-order-hold" interpolation a.k.a "nearest neighbor"
Why don't you try interp
with method 'nearest'
?
Upvotes: 1
Reputation: 518
What you can do is use interp1 function. This function will fit in deifferent way the numbers for a new X series. For example if you have x=[1 3 5 6 10 12] y=[15 20 17 33 56 89]
This means if you want to fill in for x1=[1 2 3 4 5 6 7 ... 12], you will type y1=interp1(x,y,x1)
Upvotes: 2
Reputation: 8498
You can look into fitting methods in MATLAB. For example you can look at polyfit
or splines
.
Let's look at polyfit
, the way to use it is:
P = polyfit(X,Y,N);
Here X is your time data, and Y is your GPS data measured at time values in X. And N is the order of polynomial. When you calculate P then you can use polyval
function as:
Y1 = polyval(P,X1);
Here X1 are uniform time samples for example X1=[1 2 3 4 5 6 7 8] in your case and Y1 will be the estimated data at those times, P is what you calculated using polyfit
.
Upvotes: 2