Data is in MESHGRID format, NDGRID format is required. INTERP2 help please!
조회 수: 19 (최근 30일)
이전 댓글 표시
Hello,
I am trying to interpolate 2d data along a satellite track using the following code:
or yr = 1993%:2010; yr load(['/work/uo0122/u253082/Mat_Time/ssh_',num2str(yr),'.mat']); i = i+1 size(ssh_int,1); mask = ones(3600,1682,size(ssh_int,1));
%X = X'; Y = Y'; V = V'; F = griddedInterpolant(X,Y,V)
for day = 1:size(ssh_int,1);
mask(:,:,day) = mask50;
ma = permute(mask,[3 1 2]);
%f = ndgrid(ma);
m50m(:,:,day)=interp2(lonrep,latrep,squeeze(mask(:,:,day)),REF_lon,REF_lat,'linear');
end
end
where lonrep,latrep,REF_lon and REF_lat = 3600 x 1682 matrix and mask = 3600 x 1682 x 365.
This should in theory work as I have been told it works with other data. When I run this script it complains:
Error using griddedInterpolant
Data is in MESHGRID format, NDGRID format is required. Convert your data as follows: X = X'; Y = Y'; V = V'; F = griddedInterpolant(X,Y,V)
Error in interp2/makegriddedinterp (line 220) F = griddedInterpolant(varargin{:});
Error in interp2 (line 133) F = makegriddedinterp(X, Y, V, method);
Error in depth_criterion (line 52) m50m(:,:,day)=interp2(lonrep,latrep,squeeze(mask(:,:,day)),REF_lon,REF_lat,'linear');
I have tried converting to ndgrid and to meshgrid but didn't work and tried other things with no luck.
Can someone please help me???
thanks, Michael
댓글 수: 0
채택된 답변
dpb
2014년 6월 7일
...any ideas how I should rearrange the data?
I don't quite follow your words :) on the ordering but what you need is like the examples in meshgrid
Note that the two vectors x,y into meshgrid are each sorted (hence "monotonic") and then it builds the appropriate grid from them for you. You'll need to then select the Z data to correspond to those locations and have a full dataset for interp2
댓글 수: 0
추가 답변 (1개)
dpb
2014년 6월 7일
...
m50m(:,:,day)=interp2(lonrep,latrep,squeeze(mask(:,:,day)),REF_lon,REF_lat,'linear');
You don't show how lonrep/latrep are obtained; one presumes they're in the .mat file?
Anyway, as the doc for interp2 says...
I = interp2(X,Y,Z,XI,YI) returns matrix ZI containing elements corresponding to
the elements of XI and YI ... X and Y must be monotonic, and have the same format ("plaid") as if they were produced by meshgrid. ..."
One presumes that the generation of these wasn't performed by the use of meshgrid but perhaps were just read from some other data source. More than likely the issue is that the coordinates weren't actually ordered so that the resulting grid isn't monotonic in each direction.
You'll have to look at the structure of the dataset and rearrange it. That this dataset isn't consistent and another seems to work is indicative that there's the likely root cause--they "working" and "nonworking" datasets weren't created consistently with each other.
You can test this for the arrays by
all(all(diff(lonrep,[],2)>0))
all(all(diff(latrep)>0))
If either (or both) of these return(s) FALSE (0) there's your problem (and the crystal ball is betting on it... :) )
참고 항목
카테고리
Help Center 및 File Exchange에서 CubeSat and Satellites에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!