netcdf.putAtt
Write data to netCDF attribute
Syntax
netcdf.putAtt(ncid,varid,attrname,attrvalue)
netcdf.putAtt(ncid,varid,attrname,attrvalue,xtype)
Description
netcdf.putAtt(ncid,varid,attrname,attrvalue)
writes the attribute named
attrname
with value attrvalue
to the
netCDF variable specified by varid
. To specify a global attribute,
use netcdf.getConstant('NC_GLOBAL')
for
varid
.
ncid
is a netCDF file identifier returned by
netcdf.create
or netcdf.open
.
netcdf.putAtt(ncid,varid,attrname,attrvalue,xtype)
writes
attrvalue
as the data type specified in
xtype
. Specify the value of xtype
as:
Character vector or string scalar that contains one of the following values
Value of xtype
MATLAB® Class NC_DOUBLE
double
NC_FLOAT
single
NC_INT64
(netCDF-4 files only)int64
NC_UINT64
(netCDF-4 files only)uint64
NC_INT
int32
NC_UINT
(netCDF-4 files only)uint32
NC_SHORT
int16
NC_USHORT
(netCDF-4 files only)uint16
NC_BYTE
int8
NC_UBYTE
(netCDF-4 files only)uint8
NC_CHAR
char
NC_STRING
(netCDF-4 files only)string
Equivalent numeric value returned by the
netcdf.getConstant
functionNumeric type identifier returned by the
netcdf.defVlen
function (for attributes of the user-definedNC_VLEN
types that correspond to cell arrays)
Note
You cannot use netcdf.putAtt
to set the
'_FillValue'
attribute of netCDF4 files. Use the
netcdf.defVarFill
function to set the fill value for a
variable.
The netcdf.putAtt
function corresponds to several attribute I/O functions
in the netCDF library C API. To use this function, you should be familiar with the
netCDF programming paradigm.
Examples
Tips
If
attrvalue
has more than one dimension, then thenetcdf.putAtt
function flattensattrvalue
in column-major order before writing the attribute value. For example, specifyingattrvalue
as[1 2 3; 4 5 6]
and specifyingattrvalue
as[1 4 2 5 3 6]
have the same effect.Additionally, for variables of type
NC_VLEN
, ifattrvalue
contains any entries that have more than one dimension, then thenetcdf.putAtt
function flattens those entries in column-major order before writing the values. For example, for a variable of typeNC_VLEN
, specifyingattrvalue
as{[0.5 0.3]; [0 -0.7 5.2; 4.6 2.5 1.8]}
and specifying
attrvalue
as{[0.5; 0.3] [0; 4.6; -0.7; 2.5; 5.2; 1.8]}
have the same effect.