[英]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.