フィルターのクリア

modifying the shape or dimension of the netcdf datafile

16 ビュー (過去 30 日間)
Aib E
Aib E 2018 年 2 月 19 日
コメント済み: KSSV 2018 年 2 月 28 日
a

回答 (1 件)

KSSV
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 件のコメント
Aib E
Aib E 2018 年 2 月 20 日
Thank you very much, KSSV. I tried the code as per your suggestion. Its still giving me the following error.
Error using nccreate (line 133)
'Xc' exists in file. Can not modify existing variables.
Error in re_re_reshape (line 9)
nccreate(file2,'Xc','Dimensions',{'Xc',1,length(Xc)});
Could you please let me know how I can resolve the error? Thank you
KSSV
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 ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by