Sort entire 3D matrix
4 ビュー (過去 30 日間)
古いコメントを表示
Hello.
I have a 3D matrix: A( 5,5,10). For example if I have:
A(:,:,1) = [ 43 , 432 ,2, 34,3;
323 ,44,1, 9, 7 ]
Can I obtain an output like this:
A(:,:,1) = [ 1,2,3,7,9;
34,43,44,323,432]
If yes, how? Thanks!
0 件のコメント
採用された回答
Dhruv G
2021 年 7 月 19 日
You'd have to flatten the matrix into a 1d vector, sort that, then reshape it back to the initial shape. See https://in.mathworks.com/help/matlab/ref/reshape.html for how to reshape an array, and https://in.mathworks.com/help/matlab/ref/sort.html for how to sort. The code would be something like:
a = reshape(A, [250,1])
a = sort(a)
A = reshape(a, [5,5,10])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!