Filter löschen
Filter löschen

ncwrite error dimension does not have an associated length specified

6 Ansichten (letzte 30 Tage)
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) ;

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Okt. 2023
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]}

Weitere Antworten (0)

Kategorien

Mehr zu Weather and Atmospheric Science finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by