Transmit a Structure from MATLAB to C
Show older comments
Hello everyone. I want to transmit a MATLAB structure to C. Like:
a.para1=1;
a.para2=2;
...
In my C code, I want to use these parameters to do my futher work. The current code I used is
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
double *pointerlhs, *pointerrhs[2]; /* pointer to real data in new array */
mwSize index;
/* Check for proper number of arguments. */
if (nrhs != 1) {
mexErrMsgTxt("This function takes one input arguments.");
}
/* Create an m-by-n mxArray; you will copy existing data into it */
plhs[0] = mxCreateNumericMatrix(1, 2, mxDOUBLE_CLASS, mxREAL);
//pointerrhs[1] = mxGetPr(prhs[0]);
pointerlhs = mxGetPr(plhs[0]);
/* Copy data into the mxArray */
for (index = 0; index < 2; index++) {
pointerrhs[index]= mxGetPr(prhs[index]);
pointerlhs[index] = *pointerrhs[index];
}
return;
}
which meed to tramsmit the value of the structure one by one like:
Transmit_Function(a.para1,a.para2...)
How can I get all parameters in a structure while just use one input in my MATLAB code. Like:
Transmic_Function(a)
Then I can get and use all the paramters in a.
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!