How can i reorder NxM matrix into a 1D array
1 回表示 (過去 30 日間)
古いコメントを表示
I am looking to take a sample matrix below. The matrix will be large and looking for fast and non looping solution. Thank you.
a=[1 2 3;4 5 6;7 8 9];
reshape it into:
b=[7 8 9 4 5 6 1 2 3];
採用された回答
Star Strider
2018 年 6 月 12 日
b = reshape(a([3 2 1],:)', 1, [])
b =
7 8 9 4 5 6 1 2 3
1 件のコメント
Stephen23
2018 年 6 月 12 日
Or generalized for any number of rows:
reshape(a(end:-1:1,:).', 1, [])
その他の回答 (1 件)
Alfonso
2018 年 6 月 12 日
Without looping you can do:
b = [a(end,:), a(end-1,:), a(end-2,:)]; % 1D array
b =
7 8 9 4 5 6 1 2 3
You can repeat the iterations as many rows you have: [a(end-1,:), ... ,a(end-50,:)]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!