How can I sort a matrix elementwise ?
이전 댓글 표시
Hi, I need to sort a matrix elementwise and get the results to a single vector without losing the index of each element.
For example,
A = [3, 4 ; 6, 2]
The sorted vector should be ,
B = [2;3;4;6]
without losing the information of each and every element in the original matrix.
Thank you.
채택된 답변
추가 답변 (1개)
Stephan
2019년 10월 21일
B = sort(reshape(A,[],1))
댓글 수: 3
Gayan Lankeshwara
2019년 10월 21일
Stephan
2019년 10월 21일
[B, idx] = sort(reshape(A,[],1))
[row,col] = ind2sub([size(A,1), size(A,2)],idx)
Gayan Lankeshwara
2019년 10월 21일
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!