netcdf.defVar
Create netCDF variable
Syntax
varid = netcdf.defVar(ncid,varname,xtype,dimids)
Description
varid = netcdf.defVar(ncid,varname,xtype,dimids)
creates a new variable
in the data set identified by ncid
.
varname
is a character vector or string scalar that specifies the name of the variable.xtype
specifies the NetCDF data type of the variable, using one of these values.Value of xtype
MATLAB® Class "NC_DOUBLE"
double
"NC_FLOAT"
single
"NC_INT"
int32
"NC_SHORT"
int16
"NC_BYTE"
int8
"NC_CHAR"
char
"NC_INT64"
(*)int64
"NC_UINT64"
(*)uint64
"NC_UINT"
(*)uint32
"NC_USHORT"
(*)uint16
"NC_UBYTE"
(*)uint8
"NC_STRING"
(*)string
(*) These values of
xtype
are valid only for sources with formatnetcdf4
.You can specify
xtype
as a numeric value returned by thenetcdf.getConstant
function.For attributes of the user-defined
NC_VLEN
types that correspond to MATLAB cell arrays, you can specifyxtype
as a numeric value returned by thenetcdf.defVlen
function.dimids
specifies a list of dimension IDs.netcdf.defVar
returnsvarid
, a numeric identifier for the new variable.
This function corresponds to the nc_def_var
function in the NetCDF library
C API. Because MATLAB uses FORTRAN-style ordering, the fastest-varying dimension comes first and the
slowest comes last. Any unlimited dimension is therefore last in the list of dimension IDs.
This ordering is the reverse of that found in the C API. To use this function, you should be
familiar with the NetCDF programming paradigm.
Examples
Tips
MATLAB interprets data as column major, but the netCDF C API interprets data as row major. Multidimensional data in the netCDF C API shows dimensions in the reverse of the order shown by MATLAB and consequently appears transposed.