Change a 3D matrix to a stacked 2D matrix
52 次查看(过去 30 天)
显示 更早的评论
I have a matrix of (5*5*14680) dimensions, basically 14680 of five by five matrices, I need to convert this output to a 2D matrix (I believe) so basically all the rows are stacked up, and the new matrix dimension will then be : 73400*5. I tried this out = reshape(permute(in, [1:14680]), [], 5); but the output matrix was did not seem correct, everything was out of order. Any suggestions? Please.
0 个评论
回答(2 个)
Guillaume
2016-5-6
Your permute does not make much sense and implies that there are 14680 dimensions instead of three. Since all the dimensions are listed ordered, it actually does not swap any of them. Here is the way to do it with reshape:
out = reshape(permute(in, [2 1 3]), size(in, 2), [])'
You need to transpose rows and columns before and after the reshape since matlab operates column-wise.
If thinking in terms of reshape and permute hurts your head (it does for me), it is simpler to go through a cell array and plain concatenation. The downside is speed:
out = num2cell(in, [1 2]); %split into cell array keeping dimensions 1 and 2 together
out = vertcat(out{:}) %concatenate all the cells vertically
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!