# How to regrid 2 surface data to match each other

8 views (last 30 days)
Sarvesh on 14 Aug 2024
Commented: Sarvesh on 14 Aug 2024
Hi,
Soo I have been going on for a bit with this issue. I have a set of wind data for the Australian region that I want to process. This data includes longitude, latitude, and wind speeds in both the x-direction and y-direction. Specifically, the x-direction data is represented by ulon, ulat, and uwind, while the y-direction data is represented by vlat, vlon, and vwind.
I want to calculate the resultant wind speed using the Pythagorean theorem. To do this, the dimensions of the u and v data need to be aligned, which is not the case currently.
How can I write a script to regrid the data so that the dimensions of the u variables match those of the v variables. And for a single lon/lat pair there should be a uwind and vwind.
The results should be stored as rlat, rlon, and rwind, where rlat and rlon are the regridded latitude and longitude, and rwind is the resultant wind speed.

Ronit on 14 Aug 2024
Hi Sarvesh,
I understand you want to process a set of wind data, which includes latitude, longitude, and wind speeds in both the x-direction (u) and y-direction (v). To calculate the resultant wind speed using the Pythagorean theorem, the dimensions of the 'u' and 'v' data need to be aligned. Below is a MATLAB script that regrids the data so that the dimensions of the 'u' variables match those of the 'v' variables.
% Create a common grid that spans the range of both ulat/vlat and ulon/vlon
commonLat = linspace(max(min(data.ulat), min(data.vlat)), min(max(data.ulat), max(data.vlat)), min(length(data.ulat), length(data.vlat)));
commonLon = linspace(max(min(data.ulon), min(data.vlon)), min(max(data.ulon), max(data.vlon)), min(length(data.ulon), length(data.vlon)));
% Create a common meshgrid
[CommonLon, CommonLat] = meshgrid(commonLon, commonLat);
% Store the results of common latitude and longitude
rlat = CommonLat(:,1);
rlon = CommonLon(1,:);
Now interpolate both 'uwind' and 'vwind' data onto the common grid using 'interp2' and then using the Pythagorean theorem to combine the 'u' and 'v' wind components, calculate the resultant wind speed.
% Interpolate uwind and vwind to the common grid
UwindInterp = interp2(data.ulon, data.ulat, data.uwind, rlon, rlat, 'linear');
VwindInterp = interp2(data.vlon, data.vlat, data.vwind, rlon, rlat, 'linear');
% Calculate the resultant wind speed
rwind = sqrt(UwindInterp.^2 + VwindInterp.^2);
Here are the documentation links for the functions used above:
Hope this helps!
Sarvesh on 14 Aug 2024
Hi @Ronit,
Just what i needed. Thanks heaps!

### Categories

Find more on Fractals in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!