I am using the command `[A,idx] = sort(A)`

, which sorts the matrix A columnwise, which is what I want. The `idx`

matrix shows how each column of A has been sorted. Now if I try and access `B(idx)`

MATLAB assumes I am referencing `B`

in an absolute manner. This is however not what I want, I want the columns of `B`

sorted with the same scheme `A`

was sorted with.

I am therefore looking for a command that will index a matrix columnwise. Of course I can easily do this with a loop, but it seems like a pretty poor solution. I have also come up with this solution, but it's not very pretty

```
idx = idx+repmat(0:size(idx,1):size(idx,2)*size(idx,1)-1,size(idx,1),1)
```

Thanks in advance.