Writing a variable to a netcdf

조회 수: 7(최근 30일)
Daneisha Blair
Daneisha Blair 2021년 8월 27일
Hi,
I'm having an issue with adding a variable to a netcdf. The error message I've recieved is:
Error using netcdflib
The number of input elements does not match the variable size.
Error in netcdf.putVar (line 88)
netcdflib(funcstr,ncid,varid,varargin{:});
Error in netcdf.putVar(ncid,varid,div2);
Here's my script I'm using:
% Create a netCDF file.
ncid = netcdf.create('foo.nc','NC_WRITE');
% Define a dimension in the file.
dimid = netcdf.defDim(ncid,'my_dim',length(div2));
% define a new variable in the file
varid=netcdf.defVar(ncid,'divergence','NC_FLOAT',dimid);
% Leave define mode and enter data mode to write data.
netcdf.endDef(ncid);
% Write data to variable.
netcdf.putVar(ncid,varid,div2);
% Re-enter define mode.
netcdf.reDef(ncid);
%create an attribute associated with the variable
netcdf.putAtt(ncid, varid, 'long_name', 'Ocean surface wind divergence');
netcdf.putAtt(ncid, varid, 'units', '1/s');
Side note: div2 is the name of the variable I would like to add to the netcdf. Its length is 205 and has a size of 205 x 141.
Any help is appreciated.

답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by