我在 MEX 中使用mxCreateSparse
.
mxArray *W;
W=mxCreateSparse(n*n,n*n,xsize,mxREAL);
double *wpoint;
wpoint=mxGetPr(W);
for(p=0;p<xsize;p++)
{
Wpoint[(returnindex1(xi[p][0],xi[p][1])-1)*n*n + (returnindex1(xj[p][0],xj[p][1]))]= exp(-df[p]/(SIGMAI*SIGMAI)) * exp(-dx[p]/(SIGMAJ*SIGMAJ));
}
来自的最大值(returnindex1(xi[p][0],xi[p][1])-1)*n*n + (returnindex1(xj[p][0],xj[p][1]))
是n*n*n*n
,我创建了维度的稀疏矩阵(n*n)X(n*n)
当我显示整个矩阵时,一些零元素是垃圾。同样对于较大的值n
,分段错误发生在wpoint
。