Convert c++ structs to mwArray, to use in c++ shared library

Hello,
I have a function in matlab which uses structs. For example, if I have the struct:
A.Header.title='myTitle';
A.Header.xlabel='Time';
A.Header.ylabe='Values';
A.Values=rand(1, 100);
A.Times=1:100;
my function takes the struct A as input, and plots it and does some other data processing and opens a GUI.
I have compiled this function with the Matlab Compiler and I want to call it from C++. In C++ I generate the struct A with C++ data, and in C++ the struct A has the exact same fields. But how can I pass the struct in C++ as input to my compiled Matlab function. I could not find a way to convert the struct in C++ to the mwArray type and make it suitable as an input for my compiled matlab code. Is there any way I can do this?
Thank you very much.

Answers (1)

3 Comments

Hello,
Thank you very much for your answer. I just have one more question.
In this example each field ("name", "phone", "hometown") has 4 elements, so the number of structs is 4.
In my case, I would like each field to have different number of elements. For example the "name" field can have 3 elements and the "phone" field may have 6. How can modify this code to accomodate such a situation?
Thank you very much.
Think of it more as a struct array with four elements, and each struct has 3 fields ("name", "phone", "hometown"). So it's not possible that "name" and "phone" have a different number of elements. How would you achieve what you need in C++? The best you can do is to set "name" to an empty string for the extra array elements that you need for "phone".
Actually, I think your question is better answered in http://www.mathworks.com/matlabcentral/answers/1152-dimension-of-fields-in-mwarray-structs

Sign in to comment.

Products

Asked:

on 9 Feb 2011

Community Treasure Hunt

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

Start Hunting!