All

I would like to sort a vector according to a given index (or permutation). 
I understand that the code below produces a false (last evaluation below) 
due to the fact that the function creates a local copy of x.
How can I modify my function such that x is in sorted differently (i.e. 
such that the argument is modified)?
Thank you in advance.


x=rand(5)
anothervector=rand(5)

mypermutation=sortperm(x)

function change_order!(x,srt)
  x=x[srt]
  nothing
end

before=copy(anothervector)
change_order!(anothervector,mypermutation)

before==anothervector[mypermutation] #false

before==anothervector #true, this should be false
before[mypermutation]==anothervector #false, this should be true

Reply via email to