pass structure from Matlab to mex

3 visualizaciones (últimos 30 días)
Saad
Saad el 25 de Jul. de 2012
Comentada: Walter Roberson el 29 de Abr. de 2020
Hi,
I have written some code in Matlab and would like to convert it to mex (C++) for now and later to C++ completely. In matlab, my function receives an array of structures as input. What is the best way for me to transfer this data from matlab to mex and then later on to C++.
The data being received as input has the following size and formatting: size(inputStruct) = 1 x 100; each structure has the following fields : size(inputStruct(1,1).a) = 10 x 10; size(inputStruct(1,1).m) = 8 x 30; size(inputStruct(1,1).b) = 1 x 8; size(inputStruct(1,1).c) = 1 x 10 (cells); where each cell contains a 30 x 30 matrix.

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 25 de Jul. de 2012
You can pass the structure on to your MEX-file as is, but the real question is how would you access the fields of the structure array (which is available as an mxArray). Once you can access the field names and values, you could potentially convert it to a C structure array. There are a few examples referred to at the bottom of this documentation page that you can follow to understand how to access mxArray structures. You might find the explore.c example particularly useful.
  3 comentarios
Walter Roberson
Walter Roberson el 29 de Abr. de 2020
Yes, that is the current version. However, that is version dependent. A version-independent page can only really work if there has never ever been any change to the documentation; otherwise the closest you could get would be a documentation page that listed all of the historical differences against the current version (which would be version dependent but in a useful way.)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by