我有以下矩阵:
const double values[3][41] = { { -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -72.385, -60.657,
-72.385, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99 }, { -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -97.597, -81.568,
-74.745, -66.323, -74.745, -81.568, -97.597, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99 },
{ -116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -107.26, -97.836, -89.451, -83.642, -78.459, -71.99,
-78.459, -83.642, -89.451, -97.836, -107.26, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99, -116.99,
-116.99, -116.99, -116.99, -116.99, -116.99, -116.99 }}
是否可以快速将其转换为values[3][41]
,同时保留值的正确性
这些值来自设备,该设备将输出写为[y][x]
而不是[x][y]
。我写了一个包装函数来调用矩阵中的值,但也许有一种方法可以反转轴。
答案 0 :(得分:0)
你只需要循环它:
const double values[3][41] = {...};
double newValues[41][3];
for(int i=0; i<3; ++i) {
for(int j=0; j<41; ++i) {
newValues[j][i] = values[i][j];
}
}
但是,这需要两倍的内存空间。也可以在内存中重新排序。