Change a 3D matrix to a stacked 2D matrix
43 ビュー (過去 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!