modifying the shape or dimension of the netcdf datafile
16 views (last 30 days)
Show older comments
Answers (1)
KSSV
on 20 Feb 2018
You need not to use such complex netcdf functions......you can achieve what you want with very simple netcdf functions of MATLAB. You need to know about ncdisp, ncwrite, ncread and nccreate. Below I have given a code which writes the output for xc, yc and DEM into a netcdf file. You can follow the same for the other variables.
file1 = 'nc_input.nc' ;
file2 = 'nc_output.nc' ;
xc = ncread(file1,'xc') ; xc = xc(:) ;
yc = ncread(file1,'yc') ; yc = yc(:) ;
DEM = ncread(file1,'DEM') ; DEM = DEM(:) ;
%%Write
% xc
nccreate(file2,'xc','Dimensions',{'xc',1,length(xc)}) ;
ncwrite(file2,'xc',xc) ;
ncwriteatt(file2,'xc','long_name','longitude of grid cell center');
ncwriteatt(file2,'xc','units','degrees_east');
ncwriteatt(file2,'xc','bounds','xv');
% yc
nccreate(file2,'yc','Dimensions',{'yc',1,length(yc)}) ;
ncwrite(file2,'yc',yc) ;
ncwriteatt(file2,'yc','long_name','latitude of grid cell center');
ncwriteatt(file2,'yc','units','degrees_north');
ncwriteatt(file2,'yc','bounds','yv');
% Bathymetry
nccreate(file2,'DEM','Dimensions',{'DEM',1,length(DEM)}) ;
ncwrite(file2,'DEM',DEM) ;
ncwriteatt(file2,'DEM','long_name','Digital Elevation Model');
ncwriteatt(file2,'DEM','units','meters');
2 Comments
KSSV
on 28 Feb 2018
This means.......file is already created and present in the folder......you are trying to write xc which is already present in the file.....you delete the file created and run the code. Delete the file present in the folder, every time you run the code.
See Also
Categories
Find more on NetCDF 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!