2

Hi I have a fairly simple matlab function. E.g.:

function [MYSTRUCT] = myfunc()
  MYSTRUCT.prop1 = 'test';
  MYSTRUCT.prop2 = 'foo';
  MYSTRUCT.prop3 = 42;
end

I compiled with the matlab compiler sdk a c++ library and added this properly to an c++ program using visual studio (all good so far).

But how do I work with the struct in c++ ? My c++ code looks like this:

//initialize matlab runtime
//initialize my function

mwArray out;
myfunc(1, out);

the function is called properly (e.g. if I add a imshowpair to the matlab function its displayed properly. so all good here)

the return value of the function thats called by c++ (myfunc()) is of the type mwArray and therefore I cannot access the "property" values (in this case "test", "foo" and '42')

How do I access them?

(I thought about an "getter" matlab function maybe, where I can pass over the return value (variable out) to get the values. Is this possible / a good idea?)

flor1an
  • 960
  • 3
  • 15
  • 33
  • A quick look into [documentation](https://uk.mathworks.com/help/compiler_sdk/cxx/mwarray.html) seems to suggest there is a Get method that will give you the value of the struct field. – Vahe Tshitoyan Jun 24 '17 at 23:11
  • hmm which get method you see is capable of it? I mean which method signature? – flor1an Jun 25 '17 at 10:08
  • `mwArray Get(const char* name, mwSize num_indices, ...)` **Description** Fetches a single element at a specified field name and index. This method may only be called on an array that is of type mxSTRUCT_CLASS. – Vahe Tshitoyan Jun 25 '17 at 15:52

0 Answers0