From Matlab to C++ Eigen matrix operations - vector normalization
将一些 Matlab 代码转换为 C .
问题(如何在 C 中):
在一个矩阵中连接两个向量。 (已经找到解决方案)
标准化每个数组("pts" col)除以它的第三个值
1 和 2 的 Matlab 代码:
1 2 3 4 5 6 7 8 | % 1. A 3x1 vector. d0, d1 double. B = [d0*A (d0+d1)*A]; % B is 3x2 % 2. Normalize a set of 3D points % Divide each col by its 3rd value % pts 3xN. C 3xN. % If N = 1 you can do: C = pts./pts(3); if not: C = bsxfun(@rdivide, pts, pts(3,:)); |
1 和 2 的 C 代码:
1 2 3 4 5 6 7 8 9 | // 1. Found the solution for that one! B << d0*A, (d0 + d1)*A; // 2. for (int i=0, i<N; i++) { // Something like this, but Eigen may have a better solution that I don't know. C.block<3,1>(0,i) = C.block<3,1>(0,i)/C(0,i); } |
编辑:
我希望这个问题现在更清楚了?2.
对于#2:
1 | C = C.array().rowwise() / C.row(2).array(); |
只有数组具有为行和列部分归约定义的乘法和除法运算符。当您将数组分配回
时,该数组将转换回矩阵