MEX problem with mxGetData
Mostrar comentarios más antiguos
Hi everyone !
I need advice to get this type of arguments:
- prhs[1] = {2, [5:12]}
- prhs[1] = {3, [ ], [1:5]}
- prhs[1] = {{4,6},[1:5], {1,8,9}, [3:6]} .
When I run the function I can find the good array with plhs[2] but I can't find the way to extract data, for further processing!
I know I have to use a pointer like mxGetData, but I'm trying every way except the good one I think !
if(nrhs==2)
{
mxArray * extraits= mxDuplicateArray(prhs[1]);
int n = mxGetN(extraits);
double * a= (double*)mxGetData(extraits);
/* Here, how can I find 2, and 5:12 for example ??? */
plhs[2]=extraits;
}
Thanks a lot !!!!
Respuesta aceptada
Más respuestas (2)
Kaustubha Govind
el 5 de Jul. de 2011
1 voto
Here, prhs[1] is a cell array, so you need to use mxGetCell to access elements of the cell array. You can then do a mxGetClassID query on each of the elements to determine how they should be handled. In your examples, the only expected types seem to be mxCELL_CLASS and mxDOUBLE_CLASS. For the former, you can recursively perform mxGetCell and examine the contents. For a double array, you can use mxGetData or mxGetPr to get the data.
Also, look at explore.c that the documentation for mxGetCell suggests as an example.
Lea L
el 6 de Jul. de 2011
0 votos
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!