netcdf.getAtt
Return netCDF attribute
Syntax
attrvalue = netcdf.getAtt(ncid,varid,attname)
attrvalue = netcdf.getAtt(ncid,varid,attname,output_type)
Description
attrvalue = netcdf.getAtt(ncid,varid,attname)
returns
attrvalue
, the value of the attribute name specified by
attname
. Specify attname
as a string scalar or
character vector. The returned attribute value attrvalue
is of the
MATLAB® data type that best matches the netCDF data type of attname
.
For more information about how MATLAB determines the best match, see More About.
attrvalue = netcdf.getAtt(ncid,varid,attname,output_type)
returns attrvalue
using the output data type specified by output_type
. Specify output_type
as one of these values:
"double"
"single"
"int64"
"uint64"
"int32"
"uint32"
"int16"
"uint16"
"int8"
"uint8"
"char"
This 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
This example opens the example netCDF file included with MATLAB, example.nc
, and gets the value of the attribute associated
with the first variable. The example also gets the value of the global variable in the
file.
% Open a NetCDF file. ncid = netcdf.open("example.nc","NC_NOWRITE"); % Get name of first variable. [varname vartype vardimIDs varatts] = netcdf.inqVar(ncid,0); % Get ID of variable, given its name. varid = netcdf.inqVarID(ncid,varname); % Get attribute name, given variable id. attname = netcdf.inqAttName(ncid,varid,0); % Get value of attribute. attval = netcdf.getAtt(ncid,varid,attname); % Get name of global attribute gattname = netcdf.inqAttName(ncid,netcdf.getConstant("NC_GLOBAL"),0); % Get value of global attribute. gattval = netcdf.getAtt(ncid,netcdf.getConstant("NC_GLOBAL"),gattname) gattval = 09-Jun-2008
More About
Tips
The
netcdf.getAtt
function returns attributes that are vectors as row vectors.