フィルターのクリア

ncwrite error dimension does not have an associated length specified

6 ビュー (過去 30 日間)
Zhang Ming Fang
Zhang Ming Fang 2023 年 10 月 24 日
回答済み: Walter Roberson 2023 年 10 月 24 日
Hi I got a problem to use ncwrite
Since I want to create a ncfile with lon(313), lat(409), time(3) and climate data. Example below
And got this error
Error using internal.matlab.imagesci.nc/createDimension
'longitude' does not have an associated length specified.
Error in internal.matlab.imagesci.nc/createDimensions (line 289)
this.createDimension(defgid, ...
Error in internal.matlab.imagesci.nc/createVariable (line 422)
this.createDimensions(groupName, dimensions);
Error in nccreate (line 170)
ncObj.createVariable(varName, varargin{:})
climate=rand(313,409,3);
lonn=rand(313,1);
latt=rand(409,1);
time=rand(3,1);
fileout='climate3.nc';
nccreate(fileout,'time','Dimensions',{'time',1,nz},'Datatype', 'double') ;
ncwrite(fileout,'time',time);
nccreate(fileout,'latitude','Dimensions',{'lat',1,ny},'Datatype', 'single')
ncwrite(fileout,'latitude',latt);
nccreate(fileout,'longitude','Dimensions',{'lon',1,nx},'Datatype', 'single');
ncwrite(fileout,'longitude',lonn);
nccreate(fileout,'climate','Dimensions',{'longitude','latitude','time'}) ;
ncwrite(fileout,'climate',climate) ;

採用された回答

Walter Roberson
Walter Roberson 2023 年 10 月 24 日
ny = 409;
nz = 3;
nx = 313;
climate=rand(nx,ny,nz);
lonn=rand(nx,1);
latt=rand(ny,1);
time=rand(nz,1);
fileout='climate3.nc';
nccreate(fileout,'time','Dimensions',{'time',1,nz},'Datatype', 'double') ;
ncwrite(fileout,'time',time);
nccreate(fileout,'latitude','Dimensions',{'lat',1,ny},'Datatype', 'single')
ncwrite(fileout,'latitude',latt);
nccreate(fileout,'longitude','Dimensions',{'lon',1,nx},'Datatype', 'single');
ncwrite(fileout,'longitude',lonn);
nccreate(fileout,'climate','Dimensions',{'lon','lat','time'}) ;
ncwrite(fileout,'climate',climate) ;
info = ncinfo(fileout)
info = struct with fields:
Filename: '/users/mss.system.gUdGvX/climate3.nc' Name: '/' Dimensions: [1×3 struct] Variables: [1×4 struct] Attributes: [] Groups: [] Format: 'netcdf4_classic' Datatypes: []
{info.Variables.Name}
ans = 1×4 cell array
{'time'} {'latitude'} {'longitude'} {'climate'}
dims = info.Variables(4).Dimensions;
{dims.Name}
ans = 1×3 cell array
{'lon'} {'lat'} {'time'}
{dims.Length}
ans = 1×3 cell array
{[313]} {[409]} {[3]}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by