Error using interp1 on non-uniform vectors
Show older comments
I'm using interp1 to interpolate some spatially non-uniform velocity data to a uniform spatial vector. My data looks something like this, with leading and trailing NaNs in the 2nd column (velocity) and real numbers in the 1st column (x-position):
data = [-5.13 NaN; -5.07 1.45; ...; 4.27 1.67; 5.03 NaN];
other_data = [-4.32 NaN; -4.14 1.57; ...; 4.25 1.89; 4.56 NaN];
I have several of these arrays of varied length with varied start and stop positions. My code grabs the smallest/largest x-values and uses them to build the grid for interpolation. For simplicity we'll say data contains the largest/smallest x values:
x_interp = [min(data(:,1)): 0.02 :max(data(:,1))].';
And the interp1 call looks like, where the first column of final_data is the x-values from x_interp:
final_data(:,i) = interp1(other_data(:,1),other_data(:,2),x_interp);
This call worked on one set of data, but not another and I'm having a hard time picking out what the difference in the data is. When I do this, I'm getting the following error message:
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp1 (line 166)
F = griddedInterpolant(X,V(:,1),method);
Any suggestions/ideas?
1 Comment
dpb
on 18 Aug 2014
W/O a set that doesn't work as a minimum, hard to tell, but -- have you accounted for the possible case of a zero-length vector or other boundary conditions? Not sure on the error itself; never gotten that particular one that I recall so don't have an experience base on which to draw.
You might want to look at John d'Errico's in_paintnan() (or similar spelling if not exact) in File Exchange. It has many options for handling NaN in vectors one of which might make your task simpler following its use...
Accepted Answer
More Answers (1)
Derek
on 19 Aug 2014
0 votes
Categories
Find more on Interpolation 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!