Main Content

netcdf.getAtt

構文

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

説明

attrvalue = netcdf.getAtt(ncid,varid,attname) は、attname で指定された名前の属性の値 attrvalue を返します。attname は string スカラーまたは文字ベクトルとして指定します。返される属性の値 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 から MATLAB データ型への変換

オプションの入力 output_type が指定されていない場合、netcdf.getAtt は、netCDF データ型に最も適合する MATLAB データ型を次の表に従って自動的に選択します。

NetCDF データ型MATLAB データ型
NC_DOUBLEdouble
NC_FLOATsingle
NC_INTint32
NC_SHORTint16
NC_BYTEint8
NC_CHARchar
NC_STRING (*)string
NC_INT64 (*)int64
NC_UINT64 (*)uint64
NC_UINT (*)uint32
NC_USHORT (*)uint16
NC_UBYTE (*)uint8
ユーザー定義の NC_VLEN 型 (*)cell

(*) これらの netCDF データ型は netcdf4 形式のファイルでのみ使用可能です。

バージョン履歴

すべて展開する