Sort entire 3D matrix

조회 수: 4 (최근 30일)
Bianca Brisc
Bianca Brisc 2021년 7월 19일
댓글: Bianca Brisc 2021년 7월 19일
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!

채택된 답변

Dhruv G
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])
  댓글 수: 1
Bianca Brisc
Bianca Brisc 2021년 7월 19일
Thank you! It is almost how I wanted it.
For the moment the sorted values are column wise, so column1 row1 has minimum value and column1 row2 has the next minimum. I wanted something like: column1 row1 and then column2 row1.
But I think I might be able to work with this.
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by