pass structure from Matlab to mex

3 views (last 30 days)
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.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 25 Jul 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 Comments
Walter Roberson
Walter Roberson on 29 Apr 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.)

Sign in to comment.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!