netcdf.getAtt - Return netCDF attribute
Syntax
attrvalue = netcdf.getAtt(ncid,varid,attname)
attrvalue = netcdf.getAtt(ncid,varid,attname,output_datatype)
Description
attrvalue = netcdf.getAtt(ncid,varid,attname) returns attrvalue,
the value of the attribute specified by the text string attname.
When it chooses the data type of attrvalue, MATLAB
attempts to match the netCDF class of the attribute. For example,
if the attribute has the netCDF data type NC_INT,
MATLAB uses the int32 class for the output data.
If an attribute has the netCDF data type NC_BYTE,
the class of the output data is int8 value.
attrvalue = netcdf.getAtt(ncid,varid,attname,output_datatype) returns attrvalue,
the value of the attribute specified by the text string attname,
using the output class specified by output_datatype.
You can specify any of the following strings for the output data
type.
| 'int' | 'double' | 'int16' |
| 'short' | 'single' | 'int8' |
| 'float' | 'int32' | 'uint8' |
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 information about netCDF contained in the NetCDF
C Interface Guide for version 3.6.2.
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-2008See Also
netcdf.inqAtt,netcdf.putAtt
 | netcdf.endDef | | netcdf.getConstant |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit