error using netcdf.putVar

조회 수: 13 (최근 30일)
Laura
Laura 2013년 4월 18일
댓글: mmYin 2018년 10월 18일
I don't see a difference when compared to the Matlab help, any idea?
MATLAB CODE
close all
clear all
nlon=180;
nlat=90;
filenc=['slope.nc']
ncid = netcdf.create(filenc,'NC_WRITE');
%creating dimensions
dimid_lon = netcdf.defDim(ncid,'longitude',nlon);
%creating variables and attributes
varid_lon = netcdf.defVar(ncid,'longitude','double',dimid_lon);
netcdf.putAtt(ncid,varid_lon,'long_name','Longitude')
netcdf.putAtt(ncid,varid_lon,'units','degrees_east')
lont=linspace(-180,180,nlon);
netcdf.putVar(ncid,varid_lon,lont);
netcdf.close(ncid)
this is the output:
Error using netcdflib
The NetCDF library encountered an error during execution of 'putVarDouble' function -
'Operation not allowed in define mode (NC_EINDEFINE)'.
Error in netcdf.putVar (line 87)
netcdflib(funcstr,ncid,varid,varargin{:});
Error in toMatlabHelp (line 15)
netcdf.putVar(ncid,varid_lon,lont);

채택된 답변

Ashish Uthama
Ashish Uthama 2013년 4월 22일
Try adding a call to end the definition using netcdf.enddef after you define the dimensions, but before you write the variable.
  댓글 수: 2
wave_buoys
wave_buoys 2017년 7월 29일
Hi,
I added: netcdf.endDef(ncid2) before the defition, but I still got an error:
Error using netcdflib The number of input elements does not match the variable size.
Error in netcdf.putVar (line 84) netcdflib(funcstr,ncid,varid,varargin{:});
Error in do_air (line 131) netcdf.putVar(ncid2,tid,stmp(:,n2:-1:1,:));
Could you please offer some help?
Thanks
aditya deshmukh
aditya deshmukh 2018년 5월 30일
Did you get any solution for the same? I am also facing the same error.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

aditya deshmukh
aditya deshmukh 2018년 5월 30일
Hello, I tried all the above techniques to solve the error but still it persisted. I freed some space in the drive where these nc files were generated and yes, it worked!!!
  댓글 수: 1
mmYin
mmYin 2018년 10월 18일
Hi, I encountered the same problem and tried your solution. It still doesn’t work. Do you know why? thx a lot!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by