3.85714

3.9 | 7 ratings Rate this file 8 Downloads (last 30 days) File Size: 2.1 KB File ID: #6756

Generalized Sorting

by Nathan Thern

 

19 Jan 2005 (Updated 21 Jan 2005)

Sort any kind of data based on user-defined criteria.

| Watch this File

File Information
Description

QUICKSORT allows the user to sort by any desired criteria. The user passes the data and a comparison function to the QUICKSORT and QUICKSORT returns an indexing vector sorted based on the comparison function.

The comparison function may be an inline function or a function handle. Function handles are an order of magnitude faster than inline functions. I use the TMP_HANDLE utility for creating temporary function handles in MATLAB 6.

QUICKSORT is implemented in m-code and uses a modified quicksort algorithm which sorts by "less than", "equal to" and "greater than". It is much slower than the builtin sort function, but also much more flexible.

MATLAB release MATLAB 5.2 (R10)
Other requirements Requires Matlab 6 or higher for function handle usage.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
08 Apr 2006 Steve Block

doesn't work

02 Jun 2006 Urban Novak

Thans, it works perfectly.

04 Mar 2007 Miks Böllér

if it "doesnt work", maybe its just you who couldnt use it... have you read the comments in m file?

18 Mar 2007 Guido Longoni

Thank you very much!

28 Jun 2007 Joe Daz

This function uses two arguments instead of one (a 1xn vector). Complicated if you just want to sort a simple vector.

12 Mar 2008 Jan Moringen

I used the quicksort function with a cellarray of objects and a comparison-function that compared a specific attribute of the objects. It worked nicely. I like how the source array is not touched but a list of indices is returned instead.

03 Feb 2011 Matthew  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
sort Nathan Thern 22 Oct 2008 07:39:53
sorting Nathan Thern 22 Oct 2008 07:39:53
miscellaneous Nathan Thern 22 Oct 2008 07:39:53
quicksort Nathan Thern 22 Oct 2008 07:39:53
utilities Nathan Thern 22 Oct 2008 07:39:54

Contact us at files@mathworks.com