Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我想将字符串向量从C ++传递给MATLAB。我尝试使用mxCreateCharMatrixFromStrings可用函数,但是它没有给我正确的行为。
所以,我有这样的事情: void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { vector stringVector; stringVector.push_back("string 1"); stringVector.push_back("string 2"); //etc... 问题是如何将这个向量传递到matlab环境? plhs[0] = ??? 我的目标是能够运行: >> [strings] = MyFunc(...) >> strings(1) = 'string 1' 回答: 将字符串向量存储为char矩阵要求所有字符串的长度均相同,并且必须将它们连续存储在内存中。 在MATLAB中存储字符串数组的最佳方法是使用单元格数组,请尝试使用mxCreateCellArray , mxSetCell和mxGetCell 。在本质上,单元格数组基本上是指向其他对象,char数组,矩阵,其他单元格数组等的指针的数组。 更多&回答... |
![]() |
![]() |