Interaction with C ++ objects through Mex files

I'm a little stuck if my current goal is possible, and if so, how to do it. I hope to interact with some C ++ classes through the Mex file, but I need instances of the objects that I refer to in order to be constant in all calls from different Mex functions. For example, suppose I do the following in a Mex initialization file:

void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    size_t nCats = (size_t) *mxGetPr(prhs[0]);

    std::vector<Cat> cats;
    for(size_t i = 0; i <nCats; i++){
         cats[i] = Cat(/* arguments to constructor*/);
    }
}

So, I initialized Cat objects from my external C ++ code. Now, later in the line, I need to update the information about my Cat objects, so in another Mex file I have

void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

     for(size_t i = 0; i < nCats; i++){
          cats[i].feed(/*parameters to feed method*/);
     }
}

Here are my questions:

  • std::vector Mex? -Matlab Mex ( ), Mathworks , Mex , , . std::vector , , ? ?

  • Matlab? , Matlab ++, , Matlab . , ++ , Matlab, .

+4
1
+2

Source: https://habr.com/ru/post/1688177/


All Articles