netcdf.getAtt
返回 netCDF 属性
语法
attrvalue = netcdf.getAtt(ncid,varid,attname)
attrvalue = netcdf.getAtt(ncid,varid,attname,output_type)
说明
attrvalue = netcdf.getAtt(ncid,varid,attname) 返回 attrvalue,即由 attname 指定的属性名称的值。将 attname 指定为字符串标量或字符向量。返回的属性值 attrvalue 属于与 attname 的 netCDF 数据类型最匹配的 MATLAB® 数据类型。有关 MATLAB 如何确定最佳匹配的详细信息,请参阅详细信息。
attrvalue = netcdf.getAtt(ncid,varid,attname,output_type) 使用 output_type 指定的输出数据类型返回 attrvalue。可将 output_type 指定为以下值之一:
"double""single""int64""uint64""int32""uint32""int16""uint16""int8""uint8""char"
此函数对应于 NetCDF 库 C API 中的几个属性 I/O 函数。要使用此函数,应该熟悉 netCDF 编程范式。
示例
本例打开 MATLAB 所含的 netCDF 示例文件 example.nc 并获取与第一个变量关联的属性值。本例还会获取文件中的全局变量值。
% 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详细信息
提示
netcdf.getAtt函数以行向量形式返回作为向量的属性。