This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Return netCDF attribute


attrvalue = netcdf.getAtt(ncid,varid,attname)
attrvalue = netcdf.getAtt(ncid,varid,attname,output_datatype)


attrvalue = netcdf.getAtt(ncid,varid,attname) returns attrvalue, the value of the attribute name contained in attname. Specify attname as a character vector. 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.


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. See netcdf for more information.


This example opens the example netCDF file included with MATLAB,, 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 ='','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 =

Was this topic helpful?