pass structure from Matlab to mex
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Saad
le 25 Juil 2012
Commenté : Walter Roberson
le 29 Avr 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.
0 commentaires
Réponse acceptée
Kaustubha Govind
le 25 Juil 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 commentaires
Royi Avital
le 29 Avr 2020
Walter Roberson
le 29 Avr 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.)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!