mxGetProperty (C および Fortran)
MATLAB オブジェクトのパブリック プロパティの値
C 構文
#include "matrix.h" mxArray *mxGetProperty(const mxArray *pa, mwIndex index, const char *propname);
Fortran 構文
#include "fintrf.h" mwPointer mxGetProperty(pa, index, propname) mwPointer pa mwIndex index character*(*) propname
引数
paオブジェクトである
mxArrayへのポインター。indexオブジェクト配列の目的の要素のインデックス。
C では、
mxArrayの最初の要素は0のindexをもっています。最後の要素のindexはN-1です。ここで、Nは配列内の要素の数です。Fortran では、mxArrayの最初の要素のindexは1です。最後の要素のindexはNです。ここで、Nは配列内の要素の数です。propname抽出する値をもつプロパティの名前。
戻り値
成功した場合、指定された propname の mxArray へのポインター。失敗した場合、C では NULL (Fortran では 0) を返します。よくある失敗の原因には、以下があります。
存在しない
propnameプロパティを指定している。パブリックでない
propnameを指定している。indexをmxArrayの範囲外の要素に指定している。インデックス値をテストするには、mxGetNumberOfElementsを使用するか、mxGetMおよびmxGetNを使用します。不十分なヒープ領域。
説明
mxGetProperty を呼び出して、指定された要素に格納されている値を取得します。疑似 C 用語では、mxGetProperty は以下での値を返します。
pa[index].propname
mxGetProperty は値のコピーを作成します。プロパティが大量のメモリを使用する場合は、コピーの作成が問題になることがあります。値のコピーを格納するための十分なメモリ (ヒープ内) が必要です。
例
timeseries オブジェクトの名前プロパティの表示
MEX ファイル dispproperty.c を MATLAB® パス上のフォルダーに作成します。
/*=================================================================
* dispproperty.c - Display timeseries Name property
* This is a MEX file for MATLAB.
* Copyright 2013 The MathWorks, Inc.
* All rights reserved.
*=================================================================*/
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
/* Check for proper number of arguments. */
if(nrhs!=1) {
mexErrMsgIdAndTxt( "MATLAB:dispproperty:invalidNumInputs",
"One input required.");
} else if(nlhs>1) {
mexErrMsgIdAndTxt( "MATLAB:dispproperty:maxlhs",
"Too many output arguments.");
}
/* Check for timeseries object. */
if (!mxIsClass(prhs[0], "timeseries")) {
mexErrMsgIdAndTxt( "MATLAB:dispproperty:invalidClass",
"Input must be timeseries object.");
}
plhs[0] = mxGetProperty(prhs[0],0,"Name");
}
MEX ファイルをビルドします。
mex('-v','dispproperty.c')
timeseries オブジェクトを作成します。
ts = timeseries(rand(5, 4),'Name','LaunchData');
名前を表示します。
tsname = dispproperty(ts)
tsname = LaunchData
オブジェクトの色の変更
フォルダーの matlabroot/extern/examples/mexmxgetproperty.c MEX ファイルを開いてビルドします。
制限
MATLAB エンジン API でビルドされたアプリケーションなどのスタンドアロン アプリケーションでは、
mxGetPropertyはサポートされていません。datetime型のプロパティはサポートされていません。
バージョン履歴
R2008a で導入