MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sort and positon matrix element help


If I understand correctly, you want to sort the elements of a matrix and 

retaining the row/col info.m Assume the matrix is: m: We first create an 

index matrix:

ind = Table[{i, j}, {i, Length[m]}, {j, Length[m[[1]]]}]

then we "join" both matrices and flatten it to a list with elements 


t = MapThread[{#1, #2} &, {m, ind}, 2]

t = Flatten[t, 1]

Now we sort according to the first element of {number,{row,col}} :

Sort[t, #1[[1]] < #2[[1]] &]


comp.soft-sys.math.mathematica wrote:

> Hi, guys,


>         I am attacking one proble and may need your help.

>         I have a large matrix(m*n). I wanna to sort out the matrix 

> from large to small according to its element's value AND save the 

> corresponding row and column number as its position. Latter on, plot 

> out the first 20 largest value accroding to their positions.

>         Is there any good way to do this, especially take out the 

> positons of element and assocate it with the value?


  • Prev by Date: loglogplot
  • Next by Date: Re: Problem with ExpIntegralEi vs. LogIntegral
  • Previous by thread: Re: sort and positon matrix element help
  • Next by thread: Re: sort and positon matrix element help