Ich habe diese Struktur C:Wie erstellt man Strukturen in Mex-Dateien?
struct position
{
float x, y, z;
};
struct orientation
{
float x, y, z;
};
struct robot
{
position pose;
orientation or;
};
Und im Haupt nur ich
struct Roboterdaten
Die Frage ist, wie erstelle ich diese Struktur in einer mex Funktion ? Dank
EDIT 1: Was will ich in der .mat Datei erreichen, ist dies:
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
Ich war in der Lage, die Struktur bekommen, die ich brauche:
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);
}
Ich kann sehen, in Matlab ist es wie ich will, aber in robot.pos.x habe ich nur 4 für alle Werte. Es speichert nur den letzten Wert.
Haben Sie die Struktur übergeben wollen zurück zu Matlab? Oder wollen Sie diese Strukturen nur in einem Zwischenschritt eines Funktionsaufrufs verwenden? –
Ich möchte diese Strukturen in einem Zwischenschritt verwenden. Ich möchte die MAT-File API-Funktionen verwenden, um die 'Mex' Variablen in einer .mat Datei zu speichern. Wenn Sie 'MATFile * pmat 'und' mxArray * pa' angeben, rufen Sie 'memcpy ((void *) (mxGetPr (pa)), (void *) Daten, sizeof (data))' und nach 'matPutVariable (pmat," LocalDouble ", pa)'. – aripod