modifying the shape or dimension of the netcdf datafile
16 ビュー (過去 30 日間)
古いコメントを表示
回答 (1 件)
KSSV
2018 年 2 月 20 日
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 件のコメント
KSSV
2018 年 2 月 28 日
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.
参考
カテゴリ
Help Center および File Exchange で NetCDF についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!