1

I have converted a simple code to C++ using Matlab coder. However, my main problem is that I cannot get its output! How can I convert the output which is an emxArray_real_T type to a C++ array and print it?

Community
  • 1
  • 1
Sam
  • 939
  • 5
  • 14
  • 41

1 Answers1

1

C Code Interface for Dynamically Allocated Arrays

In generated code, MATLAB represents dynamically allocated data as a structure type called emxArray. An embeddable version of the MATLAB mxArray, the emxArray is a family of data types, specialized for all base types. emxArray Structure Definition

typedef struct emxArray_<baseTypedef> {
    <baseType> *data;
    int *size;
    int allocatedSize;
    int numDimensions;
    boolean_T canFreeData; 
} emxArray_<baseTypedef>;

baseTypedef is the predefined type in rtwtypes.h corresponding to baseType. For example, here is the definition for an emxArray of base type double with unknown upper bounds:

typedef struct emxArray_real_T {
    double *data;    //<<<<<<<<<<<<<<< RIGHT HERE
    int *size;
    int allocatedSize;
    int numDimensions;
    boolean_T canFreeData; 
} emxArray_real_T;

The predefined type corresponding to double is real_T. For more information on the correspondence between built-in data types and predefined types in rtwtypes.h

http://www.mathworks.com/help/fixedpoint/ug/c-code-interface-for-unbounded-arrays-and-structure-fields.html?refresh=true

user3528438
  • 2,737
  • 2
  • 23
  • 42
  • I know about this, but as I said, my main problem is a practical solution (code) that can give me the output. – Sam Oct 06 '15 at 16:53
  • @Sam, does [this answer](http://stackoverflow.com/a/24271438/3297440) for an example of allocating `emxArray` inputs and outputs help? [This answer](http://stackoverflow.com/a/32191965/3297440) talks about copying from a `std::vector< std::vector >` to an `emxArray` and you just need to do the reverse. Remember, the data in the `emxArray` will be in column-major order. – Ryan Livingston Oct 07 '15 at 00:47
  • @RyanLivingston: Thanks for those links, I had seen them before and actually could not use them! My function simply is C = A + B, where A and B are two 2D matrices. As I mentioned, I really don't know that how I should extract the output from the matlab generated C++ code! – Sam Oct 07 '15 at 05:29