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 griddedInterpolantThe 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?
Best Answer