how to find the indices after sorting columns of a matrix
    9 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Danish Nasir
 am 31 Mai 2022
  
    
    
    
    
    Beantwortet: SALAH ALRABEEI
      
 am 31 Mai 2022
            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 Kommentare
Akzeptierte Antwort
  SALAH ALRABEEI
      
 am 31 Mai 2022
        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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
