MATLAB Answers

I need correct syntax of interpolation in this case

83 views (last 30 days)
BN
BN on 5 May 2020
Commented: BN on 6 May 2020
Hello, I have a 40x32x360 double array. (latitude x longitude x time) which presents precipitation for these latitudes and longitude for 360 months.
I want to interpolate this array to found how much the precipitation value for latitude = 30.3772 and longitude 38.2147 in all 360 months (the output is 1x1x360 array).
I read about interp2 and interp3 but I don't know what is suitable in this case and how to use them. Can you tell me what is the true syntax in order to do this?

Accepted Answer

S. Walter
S. Walter on 5 May 2020
Behzad,
You'll want to make sure your latitude, longitude, and time are all 40x32x360 arrays. For that you can use ndgrid (https://www.mathworks.com/help/matlab/ref/ndgrid.html) if they are not.
In your case, you'd want something along these lines:
% Create a interpolation surface that uses latitude, longitude,
% and time to interpolate over precipitation
F = griddedInterpolant(lat,long,t,precipitation)
% Pick the time of interest
tOfInterest = [1:1:360]';
% Pick the latitude and longitude of interest but make sure
% it's the same size as your time vector
latOfInterest = 30.3772*ones(size(tOfInterest));
longOfInterest = 38.2147*ones(size(tOfInterest));
% Now interpolate to those values
AnswerYouAreLookingFor = F(latOfInterest,longOfInterest,tOfInterest)
Hope that helps!
  3 Comments
BN
BN on 6 May 2020
Dear S. Walter,
I really appreciate you, you are really helped me, Thanks.

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!