Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用c+输出矩阵+;和墨西哥 我的C++代码有问题。我想从我的cpp程序返回一个k维矩阵到Matlab_C++_Matlab_Mex - Fatal编程技术网

用c+输出矩阵+;和墨西哥 我的C++代码有问题。我想从我的cpp程序返回一个k维矩阵到Matlab

用c+输出矩阵+;和墨西哥 我的C++代码有问题。我想从我的cpp程序返回一个k维矩阵到Matlab,c++,matlab,mex,C++,Matlab,Mex,我要传递的矩阵存储在all_data中,是一个大小为(npoints+1)x ndims的矩阵 我一直在寻找如何做到这一点,并提出: //send back points vector< vector <double> > indexes = mxGetPr(plhs[0]); for (int i=0; i < (npoints1+1); i++) for (int j=0; j < ndims1; j++)

我要传递的矩阵存储在
all_data
中,是一个大小为
(npoints+1)x ndims
的矩阵

我一直在寻找如何做到这一点,并提出:

    //send back points
    vector< vector <double> > indexes = mxGetPr(plhs[0]);
    for (int i=0; i < (npoints1+1); i++)
            for (int j=0; j < ndims1; j++)
                indexes[ i ][ j ] = all_data[ i ][ j ];

有人能帮我吗?非常感谢

看起来mxGetPr正在返回一个指向一个双精度数组的指针,您正在将其分配给一个向量向量

这应该起作用:

double* indexes = mxGetPr(plhs[0]);

看起来mxGetPr正在返回一个指向双精度数组的指针,您正在将其分配给一个向量向量

这应该起作用:

double* indexes = mxGetPr(plhs[0]);

mxGetPr
不返回
向量
。它返回一个
双精度*
。MATLAB数组连续存储在内存中,主列。假设您已经创建了具有正确尺寸的plhs[0],那么您需要做的就是:

double *indexes = mxGetPr(plhs[0]);
for (int i=0; i < (npoints1+1); i++)
    for (int j=0; j < ndims1; j++)
        indexes[i + ndims1*j] = all_data[ i ][ j ];
double*索引=mxGetPr(plhs[0]);
对于(int i=0;i<(npoints1+1);i++)
对于(int j=0;j

请注意将两个索引转换为线性偏移。

mxGetPr
不返回
向量。它返回一个
双精度*
。MATLAB数组连续存储在内存中,主列。假设您已经创建了具有正确尺寸的plhs[0],那么您需要做的就是:

double *indexes = mxGetPr(plhs[0]);
for (int i=0; i < (npoints1+1); i++)
    for (int j=0; j < ndims1; j++)
        indexes[i + ndims1*j] = all_data[ i ][ j ];
double*索引=mxGetPr(plhs[0]);
对于(int i=0;i<(npoints1+1);i++)
对于(int j=0;j

请注意将两个索引转换为线性偏移。

是否确定索引[i+ndims1*j]?我想我*(npoints1+1)+j。但我可能错了。在正常情况下,是的,你是对的。但是在MATLAB中,数组的存储位置与我们期望的位置不同。所以x(2,6)就在x(3,6)的旁边。这就是“主修专栏”的意思。这是FORTRAN时代的遗留问题。您确定索引[i+ndims1*j]吗?我想我*(npoints1+1)+j。但我可能错了。在正常情况下,是的,你是对的。但是在MATLAB中,数组的存储位置与我们期望的位置不同。所以x(2,6)就在x(3,6)的旁边。这就是“主修专栏”的意思。这是FORTRAN时代的遗留问题。