![]() |
如何在MATLAB中创建字符串数组?
我想将字符串向量从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' [B]回答:[/B] 将字符串向量存储为char矩阵要求所有字符串的长度均相同,并且必须将它们连续存储在内存中。 在MATLAB中存储字符串数组的最佳方法是使用单元格数组,请尝试使用mxCreateCellArray , mxSetCell和mxGetCell 。在本质上,单元格数组基本上是指向其他对象,char数组,矩阵,其他单元格数组等的指针的数组。 [url=https://stackoverflow.com/questions/2867340]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:05。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.