私はこのC構造を有する:mexファイルに構造を作成するには?
struct position
{
float x, y, z;
};
struct orientation
{
float x, y, z;
};
struct robot
{
position pose;
orientation or;
};
そしてメインに、私はちょうど
構造体のロボットのデータを使用し
質問は、私はMEX関数でその構造を作成するにはどうすればよいです? おかげ
EDIT 1: 私は.MATファイルで達成したいことはこれです:
robot <1x5 struct>
robot(1,1) <1x1 struct>
robot(1,1).position <1x1 struct>
x
y
z
robot(1,1).orientation <1x1 struct> with x,y and z fields
x
y
z
robot(1,2) <1x1 struct>
robot(1,2).position <1x1 struct> with x,y and z fields
x
y
z
robot(1,2).orientation <1x1 struct> with x,y and z fields
x
y
z
.
.
.
robot(1,5) <1x1 struct>
robot(1,5).position <1x1 struct> with x,y and z fields
x
y
z
robot(1,5).orientation <1x1 struct> with x,y and z fields
x
y
z
私は私が必要とする構造を得ることができました。私が見ることができる
double values[5] = {1,2,3,4}; //Just for testing.
const char *field_robot[] = {"pos", "or"};
const char *field_coordinates[] = {"x", "y", "z"};
mxPos = mxCreateStructMatrix(1,1,3, field_coordinates);
mxOr = mxCreateStructMatrix(1,1,3, field_coordinates);
mxRobot = mxCreateStructMatrix(1,1,5, field_robot);
for(i=0; i<5; i++)
{
mxSetFieldByNumber(mxPos, 0, 0, mxCreateDoubleScalar(values[i]));
mxSetFieldByNumber(mxRobot, i, 0, mxPos);
}
をmatlabでそれは私が望む方法ですが、robot.pos.xの中で私はすべての値に対して4つしか持っていません。最後の値を保存するだけです。
は、あなたが戻って構造を通過したいですか:あなたはMathWorks社のサイトでオンラインドキュメントを見つけることができます
:あなたはコマンドでMATLABでソースファイル全体を表示することができますMatlab?あるいは、関数呼び出しの中間段階でこれらの構造体を使用したいだけですか? –
これらの構造を中間段階で使用したいと考えています。私は、MATファイルAPI関数を使用して、 'mex'変数を.matファイルに格納したいと考えています。 'matFut * pmat'と' mxArray * pa'を宣言すると、 'memPpy(void *)(mxGetPr(pa))、(void *)data、sizeof(data))'と 'matPutVariable(pmat、" LocalDouble "、pa)'。 – aripod