pass structure from Matlab to mex

1 回表示 (過去 30 日間)
Saad
Saad 2012 年 7 月 25 日
コメント済み: Walter Roberson 2020 年 4 月 29 日
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.

採用された回答

Kaustubha Govind
Kaustubha Govind 2012 年 7 月 25 日
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 件のコメント
Royi Avital
Royi Avital 2020 年 4 月 29 日
Walter Roberson
Walter Roberson 2020 年 4 月 29 日
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.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by