I need correct syntax of interpolation in this case

1 visualización (últimos 30 días)
BN
BN el 5 de Mayo de 2020
Comentada: BN el 6 de Mayo de 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?

Respuesta aceptada

S. Walter
S. Walter el 5 de Mayo de 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 comentarios
S. Walter
S. Walter el 5 de Mayo de 2020
Your data is in vectors, not arrays. You will have to use ndgrid to convert it from vectors to arrays.
You can check your variables by using the "whos" command:
whos
and the output you'll get is:
Name Size Bytes Class Attributes
dates 360x1 2880 datetime
lati 1x32 128 single
loni 1x40 160 single
precipitation 40x32x360 1843200 single
If you look at the "Size" column, it shows you "dates" is 360x1, "lati" is 1x32, and "loni" is 1x40. But what you're interested in interpolating over is 40x32x360. The interpolator doesn't know how to organize those vectors into a matrix, the programmer will have to do that. In order to create that matrix, you use the ndgrid function.
Looking at your data though, you can see precipitation is 40x32x360 - meaning it's organized as longitude by latitude by date. When you go to use ndgrid, you have to keep that same ordering
[x,y,z] = ndgrid(loni,lati,dates);
When you do that, you should see that x, y, and z are now the same size as precipitation. When you then organize your griddedInterpolant, you will have to keep the same order
F = griddedInterpolant(x,y,z,precipitation)
But Wait! The other part of your problem is that, looking at the "Class" column of your variables - dates is in datetime format. The interpolator is not set up to handle classes other than single or double. So you'll have to find a way to convert the "dates" variable into a numerical value. I can't help you how to do that, it depends on the rest of your code.
Lastly! Make sure when you go to use the interpolator you just created, you always keep the same order - longitude, latitude, dates - otherwise you will receive an erroneous answer.
BN
BN el 6 de Mayo de 2020
Dear S. Walter,
I really appreciate you, you are really helped me, Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Time Series Events en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by