bool MatlabEngine::PutCells( const string& inExp, const StringMatrix& inValue ) { int sizeDim2 = inValue.empty() ? 0 : inValue[ 0 ].size(); mxArray* mat = mxCreateCellMatrix( inValue.size(), sizeDim2 ); int indices[] = { 0, 0 }; for( size_t i = 0; i < inValue.size(); ++i ) { indices[ 0 ] = i; for( size_t j = 0; j < inValue[ i ].size(); ++j ) { indices[ 1 ] = j; int idx = mxCalcSingleSubscript( mat, 2, indices ); mxDestroyArray( mxGetCell( mat, idx ) ); mxArray* val = mxCreateString( inValue[ i ][ j ].c_str() ); mxSetCell( mat, idx, val ); } } bool success = PutMxArray( inExp, mat ); mxDestroyArray( mat ); return success; }
bool MatlabEngine::PutCells( const string& inExp, const StringMatrix& inValue ) { mwSize sizeDim2 = static_cast<mwSize>( inValue.empty() ? 0 : inValue[ 0 ].size() ); mxArray* mat = mxCreateCellMatrix_( static_cast<mwSize>( inValue.size() ), sizeDim2 ); mwIndex indices[] = { 0, 0 }; for( mwIndex i = 0; i < static_cast<mwIndex>( inValue.size() ); ++i ) { indices[ 0 ] = i; for( mwIndex j = 0; j < static_cast<mwIndex>( inValue[ i ].size() ); ++j ) { indices[ 1 ] = j; int idx = mxCalcSingleSubscript_( mat, 2, indices ); mxDestroyArray_( mxGetCell_( mat, idx ) ); mxArray* val = mxCreateString_( inValue[ i ][ j ].c_str() ); mxSetCell_( mat, idx, val ); } } bool success = PutMxArray( inExp, mat ); mxDestroyArray_( mat ); return success; }