This question comes after solving the problem I got in this question. I have a c++ code that processes frames from a camera and generates a matrix for each processed frame. I want to send to matlab engine each matrix, so at the end of the execution I have in stored all the matrices. I am conffused about how to do this, I send a matrix in each iteration but it is overwritting it all the time, so at the end I only have one. Here is a code example:
matrix.cpp
#include helper.h
mxArray *mat;   
mat = mxCreateDoubleMatrix(13, 13, mxREAL);     
memcpy(mxGetPr(mat),matrix.data, 13*13*sizeof(double));
engPutVariable(engine, "mat", mat);
I also tried to use a counter to dinamically name the different matrices, but it didn't work as matlab engine requires the variables to be defined first. Any help will be appreciated. Thanks.
You can create a cell array in matlab workspace like this:
    mwSize size = 10;
    mxArray* cell = mxCreateCellArray(1, &size);
    for(size_t i=0;i<10;i++)
    {
        mxArray *mat;   
        mat = mxCreateDoubleMatrix(13, 13, mxREAL);     
        memcpy(mxGetPr(mat),matrix.data, 13*13*sizeof(double));
        mwIndex subscript = i;
        int index = mxCalcSingleSubscript(cell , 1,&subscript); 
        mxSetCell(m_cell , index, mat);
   }
   engPutVariable(engine, "myCell", cell);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With