MATLAB:将 3D 转换为 2D(串联)

MATLAB: Transform 3D into 2D (concatenation)

我需要将三维数组 s 转换为二维数组 sReshape,其中三维的每个切片都将简单地放在第一个切片的二维数组的行下方。

下面是示例以及预期的解决方案:

s = reshape((1:30),[5,3,2]);
sReshape = ???

resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]';
isequal(sReshape, resultExpected)

你可以在整形前使用permute在二次元和三次元之间切换:

s = reshape((1:30),[5,3,2]);
% switch between the 2nd and third dimensions
y = permute(s,[1 3 2]);
% reshape into 3 columns matrix
sReshape = reshape(y,[],3);

resultExpected = [(1:5),(16:20) ; (6:10),(21:25) ; (11:15),(26:30)]';
isequal(sReshape, resultExpected)