我有以下矩阵:
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]
的设备。我想写一个包装函数从矩阵调用值,但也许有一种方法来反转轴。
你只需要循环一下:
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];
}
}
但是,这需要两倍的内存空间。也可以在内存中重新排序。