How can I create a Cell Array in a MEX function which can be returned to the MATLAB workspace?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 17 de Oct. de 2017
Respondida: MathWorks Support Team
el 20 de Oct. de 2017
I would like to create a cell array in a MEX file which contains two character arrays as members of the cell array. I would also like to return this cell array to the base MATLAB workspace. How can this be done?
Respuesta aceptada
MathWorks Support Team
el 17 de Oct. de 2017
https://www.mathworks.com/help/matlab/apiref/mxcreatecellmatrix.html
Note that once the mxArray corresponding to your cell array has been created, you would may need to set cell array fields using the 'mxSetCell' function:
https://www.mathworks.com/help/matlab/apiref/mxsetcell.html
An example of this workflow is provided with MATLAB. Please execute the following command on the MATLAB Command Window:
>> edit([matlabroot '/extern/examples/mx/mxcreatecellmatrix.c']);
There is another example of this workflow with this article as "cellTest.c". This file creates a cell array with "Hello" and "Goodbye" character arrays as members of the cell array.
If you would like to return a cell array created in a MEX file to the MATLAB workspace, the recommended method is to add the new 'mxArray' to the 'plhs' array within the 'mexFunction' in the MEX file. However, if this is not sufficient for your workflow, you can also use the 'mexPutVariable' function to manually send specified variables back to the base MATLAB workspace.
https://www.mathworks.com/help/matlab/apiref/mexputvariable.html
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!