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.
Got a problem in cdtgrid function.
2 次查看(过去 30 天)
显示 更早的评论
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 个)
Amal Raj
2023-3-15
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!