MATLAB: Data is in MESHGRID format, NDGRID format is required. INTERP2 help please!

interp2interpolatinterpolationmeshgridndgridsatellitetrack;

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

Best Answer

...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