From help-octave-request at bevo dot che dot wisc dot edu Mon Nov 10 03:44:25 1997 Subject: Re: Simple Matrix Manipulation Extressions From: "John W. Eaton" To: Dirk Laurie Cc: help-octave at bevo dot che dot wisc dot edu, john@arrows.demon.co.uk (john) Date: Mon, 10 Nov 1997 03:43:19 -0600 On 10-Nov-1997, Dirk Laurie wrote: | do_fortran_indexing=1; | [x,j]=sort(A(:)); % The method works for two vectors | [x,k]=sort([x; v(:)]); | m=1:length(k); m(k)=1:length(k); | count=A; count(j)=m(1:length(j))-(1:length(j)); | | I suppose this is `a bit horrible' but it does have complexity | less than length(x)*length(v) and there are no loops. It will | not work properly if the internal sorting algorithm of octave | allows equal elements to exchange places. No, it doesn't -- Octave's sort function is based on algorithm 5.2.4L from Knuth, Volume 3, and it is stable. jwe