Got a problem in cdtgrid function.

10 Ansichten (letzte 30 Tage)
Mandip
Mandip am 27 Feb. 2023
Beantwortet: Amal Raj am 15 Mär. 2023
Could run the following code upto weights_target but got a error in cdtgrid(). line.
%creating a meshgrid for cdtarea (make sure you create (lat,lon))
[lat_source, lon_source] = meshgrid(lat, lon);
weights = cdtarea(lat_source, lon_source, 'Method', 'mean');
weights_target = cdtarea(lat_target, lon_target, 'Method', 'mean');
% Call the regrid function to interpolate the data to the target grid
tas_regrid = cdtgrid().regrid(tas, 'X', 'Y', lon_edges_target, lat_edges_target, 'Weights', weights, 'WeightsTarget', weights_target);
% Save the regridded data to a new netCDF file
new_ncfile = 'temperature_data_regrid.nc';
cdfwrite(new_ncfile, 'tas', 'Data', tas_regrid, 'Lon', lon_edges_target(1:end-1), 'Lat', lat_edges_target(1:end-1));
Got an error of :
Error using cdtgrid
Not enough output arguments. I am trying to regrid the data from another dimension to 2.5 by 2.5 with this code. Is the process right? I was also stuck in a previous line. Thanks to Chad Greene for your help.
  1 Kommentar
Mandip
Mandip am 27 Feb. 2023
in the code, lat_source and lon_source have the original values of lat and lon from the model which have dimension 128*64. Similarly, lan_target and lon_target have the value of new desired grid which is 2.5 by 2.5 which has dimension 144*72. Lan_edges_target and lot_edges_target are values of lat and lon separated by 2.5 degrees.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Amal Raj
Amal Raj am 15 Mär. 2023
Hi
I believe there is a problem with the arguments of 'cdtgrid'. Try replacing it with the code below.
tas_regrid = cdtgrid().regrid(tas, 'X', lon_source, 'Y', lat_source, 'Lon', lon_edges_target, 'Lat', lat_edges_target, 'Weights', weights, 'WeightsTarget', weights_target);

Kategorien

Mehr zu Interpolation of 2-D Selections in 3-D Grids finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by