From octave-sources-request at bevo dot che dot wisc dot edu Mon Jun 26 09:27:18 2000 Subject: sortrows.m (Re:matlab compatibility) From: Daniel Calvelo To: octave-sources at bevo dot che dot wisc dot edu Date: Mon, 26 Jun 2000 15:35:19 +0200 (CET) In http://www.che.wisc.edu/octave/mailing-lists/octave-sources/2000/93, pkienzle at kienzle dot powernet dot co dot uk remarks: [snip] . Data analysis and Fourier transforms. . . Basic operations. max - Largest component. min - Smallest component. mean - Average or mean value. median - Median value. std - Standard deviation. var - Variance. sort - Sort in ascending order. x sortrows - Sort rows in ascending order. [snip] There you are :) (I read the Matlab help to get the interface right, but the code is original.) ------------------------------------------------------------ function s = sortrows( m,c ), ## returns m sorted "lexicographically", or following the columns in ## the second argument. Set implicit_str_to_num_ok and ## implicit_num_to_str_ok to 1 if you use this for string sorting. ## Daniel Calvelo. Use modify and debug at will. if nargin<2, indices = [1:size(m,2)]'; else, indices = c(:); endif indices=flipud(indices); ii=1; while ii<=length(indices), [trash,idx] = sort( m(:,indices(ii)) ); # sort keeps the original order :) m = m( idx,: ); ii++; endwhile s = m; endfunction ------------------------------------------------------------------------ -- Daniel Calvelo Aros calvelo at lifl dot fr ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------