Main Content

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 name contained in attname. Specify attname as a character vector or string scalar. 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 name specified by attname, using the output class specified by output_datatype. Specify the output data type using one of these values.

'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 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