Reading structure fields string array of a Matlab struct in C++
2 views (last 30 days)
Show older comments
Hi,
i call a matlab dll function from my C++ code using Qt libraries. A function output is
mwArray p_function_out
In Matlab it is a structure with following fields:
sts
sing
msg() % array of 2 strings
For example:
function [vx_sts, data] = fcn(p1, p2)
... % function code
data = ...
% at the end for example
vx_sts.sts = -1;
vx_sts.sing = -101;
vx_sts.msg(1) = "err sts";
vx_sts.msg(2) = "err sing";
end
I'm trying to assign the fields of
mwArray p_function_out
to C ++ variables. For the two numeric fields I have no problem but I can't read the string array:
/* Qt C++ code */
std::shared_ptr<mwArray> p_function_out = std::make_shared<mwArray>();
std::shared_ptr<mwArray> my_data = std::make_shared<mwArray>();
int x1 = 3;
int x2 = 5;
mwArray p1((mxDouble)x1);
mwArray p2((mxDouble)x2);
fcn(2, *p_function_out, *my_data, p1, p2);
int my_sts, my_sing;
my_sts = static_cast<int>(p_function_out.Get("sts", 1, 1).Get(1, 1));
my_sing = static_cast<int>(p_function_out.Get("sing", 1, 1).Get(1, 1));
/* until here everthing works fine */
QString my_msg[2];
my_msg[0] = (p_function_out.Get("msg", 1, 1).Get(1, 1)).ToString(); // i get an exception
my_msg[1] = (p_function_out.Get("msg", 1, 1).Get(1, 2)).ToString(); // i get an exception
can anyone help me please?
Thank You
0 Comments
Answers (0)
See Also
Categories
Find more on Call MATLAB from C++ in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!