how to find the indices after sorting columns of a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Suppose i have 4x4 matrix A with different integers. I sort each column of the matrix i.e. B= sort (A,'ascend'). Now i want matrix C which should show changed indices of matrix A after sorting.
댓글 수: 0
채택된 답변
SALAH ALRABEEI
2022년 5월 31일
If I got you correctly, I think you want you want this
clear
A = magic(4)
[n,m]=size(A)
[As,Cur_ind]=sort(A,'ascend')
Org_ind = reshape(1:n*m,n,m)
bb=[1:n].*ones(n,m)
C = reshape(diag(Org_ind(Cur_ind,bb)),n,m)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!