Emma Tebbs
Emma Tebbs

Reputation: 1467

Interpolate gridded climate data in MATLAB

I have some climate data sets, one that has a spatial resolution of 0.05 degrees and the other that has a spatial resolution of 0.75 degrees. I would like to interpolate the second dataset so that it is on the same grid space as the first data i.e. 0.05 degrees.

So, my data sets have the following dimensions:

>> size(data1)

ans =

    10     8    12

>> size(data2)

ans =

    66    74    12

where the first dimension refers to the longitude, the second dimension refers to the latitude, and the third dimension refers to the temperature at that grid (the grid defined by the longitude and latitude values).

Given, that these have the same number of temperature (i.e. 12), is it possible in MATLAB to interpolate the data so that data1 has dimensions of

>> size(new_data2)

ans =

    66    74    12

Is this possible in matlab?

The reason I am doing this is that I'm trying to compare to two datasets, which are generated on different sized grids, thus I firstly need to convert them to the same grid.

Any advice is appreciated.

Example:

b = rand(5,7,12);
lon = 30:0.75:33;
lat = 50:0.75:55;

lon_needed = 30:0.05:33;
lat_needed = 50:0.05:52;

I waould like for b to be linearly inteporlated to have dimensions equal to

(length(lon_needed),length(lat_needed),12)

I tried:

Vq = interpn(lon,lat,1:12,b,lon_needed,lat_needed,'linear',-1);

but this returns an error. I am still trying a few things to make it work, but a push in the right direction would be great.

Upvotes: 2

Views: 825

Answers (1)

BillBokeey
BillBokeey

Reputation: 3476

1) You define three variables for the original grid (lon, lat and 1:12), but you don't specify the third variable for target grid (you only have lon_needed and lat_needed), so you'd better do :

Vq = interpn(lon',lat',(1:12)',b,lon_needed',lat_needed',(1:12)','linear',-1);

2) Will your latitude and longitude ranges be wide? That could impact the precision of the linear interpolation (the earth is a sphere).

Upvotes: 1

Related Questions