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

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

Kaustubha Govind
Kaustubha Govind on 9 Feb 2011
  3 Comments
Kaustubha Govind
Kaustubha Govind on 10 Feb 2011
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".
Kaustubha Govind
Kaustubha Govind on 10 Feb 2011
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

Community Treasure Hunt

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

Start Hunting!