This is machine translation

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


Return information about netCDF attribute


[xtype,attlen] = netcdf.inqAtt(ncid,varid,attname)


[xtype,attlen] = netcdf.inqAtt(ncid,varid,attname) returns the data type, xtype, and length, attlen, of the attribute identified by the text string attname.

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

varid identifies the variable that the attribute is associated with. To get information about a global attribute, specify netcdf.getConstant('NC_GLOBAL') in place of varid.

This function corresponds to the nc_inq_att function 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 information about an attribute in the file.

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

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

% Get attribute name, given variable id and attribute number.
attname = netcdf.inqAttName(ncid,varid,0);

% Get information about the attribute.
[xtype,attlen] = netcdf.inqAtt(ncid,varid,'description')

xtype =


attlen =


% Get name of global attribute
gattname = netcdf.inqAttName(ncid,netcdf.getConstant('NC_GLOBAL'),0);

% Get information about global attribute.
[gxtype gattlen] = netcdf.inqAtt(ncid,netcdf.getConstant('NC_GLOBAL'),gattname)

gxtype =


gattlen =

Was this topic helpful?