Interp2 usage with Coordinates

7 views (last 30 days)
Hello,
I have two data sets: a sea surface salinity product for the southern ocean, in a 38 x 1388 x 12 3D Array, in which the data is in 25km x 25km grid (arranged by Lat, Lon, Month). I also have an ocean mixed layer depth product for the Southern Ocean in a 41 x 720 x 12 3D Array, in which data is in a 0.5 degree x 0.5 degree grid (again arranged by lat, lon , month). In order to calculate the salinity budget I have to get these 2 data sets on to the same grid (AKA: the latitudes and longitudes need to match).
This is the code I am using to try and translate the data across onto a grid with the same coordinates as january_clim_sss (sss= sea surface salinity, mld is mixed layer depth)
I have tried this multiple times, switiching around the x ad y values, and each time get the following error notification:
Error using griddedInterpolant
Sample points vector corresponding to grid dimension 1 must contain 720 elements.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 126)
F = makegriddedinterp({X, Y}, V, method,extrap);
Error in GRIDDING (line 1)
january_mld_cor=interp2(lat_sss_so,lon_sss_so,January_Mld,lat_mld_so,lon_mld_so);
Can anyone help me with this issue?
Thanks in advance!!

Accepted Answer

Shiva Kalyan Diwakaruni
Shiva Kalyan Diwakaruni on 11 Feb 2021
Hi,
As a workaround, use in-built function 'griddedInterpolant' to achieve the same goal.
As an demonstration, refer to the following code snippet:
>>[X1,Y1] = ndgrid(X,Y);
>>F=griddedInterpolant(X1,Y1,Z,'cubic');
>>[XI,YI]=ndgrid(a,b);
>>Vq= F(XI,YI);
you can follow the below link for more information on griddedInterpolant'
thanks.

More Answers (0)

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!