From: theotheraussie Bellamy on
I want to create a complex structure in a mexFunction that will be passed back into Matlab. The desired structure in CPP is:

typedef struct
{
int num_elements;
double array1[max_num];
double array2[max_num];
int array3[max_num];
} profile1_type;

typedef struct
{
int num_elements;
double array1[max_num];
double array2[max_num];
} profile2_type;

typedef struct
{
profile1_type profile1;
profile2_type profile2;
} parameters_type;

so when I define a variable as:
parameter_type variable1;
it will consist of 2 structures that contain some arrays as well as scalars.
My question is, how do i get all these fields into a single structure variable that is populated, then assign it to the appropriate plhs[] to be passed back into Matlab.
From: Rune Allnor on
On 17 Jun, 13:49, "theotheraussie Bellamy"
<beau.bell...(a)baesystems.com> wrote:
> I want to create a complex structure in a mexFunction that will be passed back into Matlab. The desired structure in CPP is:
>
> typedef struct
> {
>    int num_elements;
>    double array1[max_num];
>    double array2[max_num];
>    int array3[max_num];
>
> } profile1_type;
>
> typedef struct
> {
>    int num_elements;
>    double array1[max_num];
>    double array2[max_num];
>
> } profile2_type;
>
> typedef struct
> {
>     profile1_type  profile1;
>     profile2_type  profile2;
>
> } parameters_type;
>
> so when I define a variable as:
> parameter_type variable1;
> it will consist of 2 structures that contain some arrays as well as scalars.
> My question is, how do i get all these fields into a single structure variable that is populated, then assign it to the appropriate plhs[] to be passed back into Matlab.

You will need to map the C(++) structures indicated above
to some equivalent matlab structure or cell array. There are
several example files shipped witrh matlab that demonstrate
how to declare and access matlab structures and cell arrays
from C(++).

Rune
From: Jan Simon on
Dear Bellamy,

> typedef struct
> {
> int num_elements;
> double array1[max_num];
> double array2[max_num];
> int array3[max_num];
> } profile1_type;
>
> typedef struct
> {
> int num_elements;
> double array1[max_num];
> double array2[max_num];
> } profile2_type;
>
> typedef struct
> {
> profile1_type profile1;
> profile2_type profile2;
> } parameters_type;

What did you try so far? Did you read the dosumentation?

mxArray *p1;
const char *parameters_type_fields = {"profile1_type", "profile2_type"};
const char *profile2_fields = {"num_elements", "array1", "array2"};
.... similar for profile1...

plhs[0] = mxCreateStructMatrix(1, 1, 2, parameters_type_fields);

p1 = ...
p2 = mxCreateStructMatrix(1, 1, 3, profile2_fields);
mxSetFieldByNumber(p2, 0, 0, <create your num_elements here>);
....
mxSetFieldByNumber(plhs[0], 0, 0, p1);
mxSetFieldByNumber(plhs[0], 0, 1, p2);

I hope this helps so far, Jan
From: James Tursa on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hvdpfo$cjj$1(a)fred.mathworks.com>...
>
> const char *parameters_type_fields = {"profile1_type", "profile2_type"};
> const char *profile2_fields = {"num_elements", "array1", "array2"};

I think you meant this:

const char *parameters_type_fields[] = {"profile1_type", "profile2_type"};
const char *profile2_fields[] = {"num_elements", "array1", "array2"};


James Tursa
From: Jan Simon on
Dear James,

> > const char *parameters_type_fields = {"profile1_type", "profile2_type"};

> I think you meant this:
> const char *parameters_type_fields[] = {"profile1_type", "profile2_type"};

Thanks for this important correction. Jan
 | 
Pages: 1
Prev: Stateflow
Next: memory usage of matlab builder NE