Writing a variable to a netcdf

조회 수: 7(최근 30일)
Daneisha Blair
Daneisha Blair 2021년 8월 27일
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)
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
% Leave define mode and enter data mode to write data.
% Write data to variable.
% Re-enter define mode.
%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.



Community Treasure Hunt

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

Start Hunting!

Translated by