[英]MATLAB: Transform 3D into 2D (concatenation)
我需要将3D数组s
转换为2D数组sReshape
,其方式是将第三维的每个切片简单地放在第一个切片的2D数组的行下方。
这是示例以及预期的解决方案:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.