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

1 次查看(过去 30 天)
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.

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-2-9
  3 个评论
Kaustubha Govind
Kaustubha Govind 2011-2-10
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 2011-2-10
Actually, I think your question is better answered in http://www.mathworks.com/matlabcentral/answers/1152-dimension-of-fields-in-mwarray-structs

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deploy to C++ Applications Using mwArray API (C++03) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by