[英]Converting this C++ code to Matlab
我正在尝试将简单的C代码转换为matlab,但是一开始我似乎很清楚地陷入了困境。 该细分市场在做什么? SIZE_N2 = 25,w = 533,h = 800
//Init the L matrix. L is a sparse matrix that only contains SIZE_N2 non-zero elements per row.
//We store the L matrix in an array with one row per image pixel and one column per non-zero value.
//Each array cell accumulates values according to equation 11.
LMatrix = new double* [w*h];
for(i=0; i<w*h; i++){
LMatrix[i] = new double[SIZE_N2];
for(j=0; j<SIZE_N2; j++){
LMatrix[i][j] = 0;
}
}
它不是在Matlab中创建此矩阵吗?
LMatrix = 0(SIZE_N2,w * h);
当我用它运行代码时,矩阵在for循环中超出范围。
任何人都知道正确的实现吗?
谢谢!
将C ++代码转换为MATLAB最直接的方法是
LMatrix = zeros(w*h, SIZE_N2)
请注意,代码中的第一个索引(行数)的大小为w*h
,您将它们交换了一下。 这就是为什么您出界错误,因为您索引错误的方式。
我还将提到C ++使用基于0的索引,而MATLAB使用基于1的索引。 这会使您绊倒,在转换代码时,必须非常非常小心地始终向索引加1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.