Main Content


Return name of netCDF attribute


attname = netcdf.inqAttName(ncid,varid,attnum)


attname = netcdf.inqAttName(ncid,varid,attnum) returns attname, a character vector containing the name of an attribute.

ncid is a netCDF file identifier returned by netcdf.create or

varid is a numeric identifier of a variable in the file. If you want to get the name of a global attribute in the file, use netcdf.getConstant('NC_GLOBAL') in place of varid. attnum is a zero-based numeric value specifying the attribute, with 0 indicating the first attribute, 1 the second attribute, and so on.

This function corresponds to the nc_inq_attname function in the netCDF library C API. To use this function, you should be familiar with the netCDF programming paradigm.


This example opens the example netCDF file included with MATLAB®,

% Open netCDF example file.
ncid ='','NC_NOWRITE');

% Get identifier of a variable in the file.
varid = netcdf.inqVarID(ncid,'avagadros_number')

% Get the name of the attribute associated with the variable.
attname = netcdf.inqAttName(ncid,varid,0)

attname =


% Get the name of the global attribute associated with the variable.
gattname = netcdf.inqAttName(ncid,netcdf.getConstant('NC_GLOBAL'),0)

gattname =