ncwrite error dimension does not have an associated length specified
6 views (last 30 days)
Show older comments
Zhang Ming Fang
on 24 Oct 2023
Answered: Walter Roberson
on 24 Oct 2023
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) ;
0 Comments
Accepted Answer
Walter Roberson
on 24 Oct 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.Variables.Name}
dims = info.Variables(4).Dimensions;
{dims.Name}
{dims.Length}
0 Comments
More Answers (0)
See Also
Categories
Find more on Weather and Atmospheric Science 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!