How to create an array of strings in matlab?

I would like to pass a string vector from C ++ to matlab. I tried using available functions like mxCreateCharMatrixFromStrings, but this does not give me the correct behavior.

So, I have something like this:

void mexFunction(
    int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[])
{
   vector<string> stringVector;
   stringVector.push_back("string 1");
   stringVector.push_back("string 2");
   //etc...

The problem is how to get this vector in matlab?

   plhs[0] = ???

My goal is to run:

>> [strings] = MyFunc(...)
>> strings(1) = 'string 1'
+3
source share
1 answer

Saving a row vector as a char matrix requires all your rows to be the same length and that they are stored in memory in memory.

MATLAB - , mxCreateCellArray, mxSetCell mxGetCell. , char , , ..

+5

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


All Articles