Error using interp1 on non-uniform vectors
이전 댓글 표시
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
dpb
2014년 8월 18일
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...
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!