Main Content

netcdf.inqAtt

返回有关 netCDF 属性的信息

语法

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

说明

[xtype,attlen] = netcdf.inqAtt(ncid,varid,attname) 返回 attname 中标识的属性的数据类型 xtype 和长度 attlen。以字符向量或字符串标量形式指定 attname

ncidnetcdf.createnetcdf.open 返回的 netCDF 文件标识符。

varid 标识该属性所关联的变量。要获取全局属性信息,请指定 netcdf.getConstant('NC_GLOBAL') 替代 varid

此函数对应于 netCDF 库 C API 中的 nc_inq_att 函数。要使用此函数,应该熟悉 netCDF 编程范式。

示例

本例打开 MATLAB® 随附的 netCDF 示例文件 example.nc 并获取该文件中某个属性的信息。

% Open netCDF example file.
ncid = netcdf.open('example.nc','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 =

     2


attlen =

    31

% 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 =

     2


gattlen =

    11