Home > wafo > misc > csort.m

# csort

Counting sorting

## SYNOPSIS

[b,I] = csort(a,amin,amax,chk)

## DESCRIPTION

``` CSORT Counting sorting

CALL [b,I] = csort(a,amin,amax)

b    = sorted vector
I    = index vector defined by b = a(I);
a    = vector of integers to sort (length N).
amin = minimum value of a (default min(a)).
amax = maximum value of a (default max(a)).

CSORT assumes that each of the N input elements is an integer. Let K
denote the range of the integers. When K = O(N) the sorting
runs in O(N) time.

Example: % Compare csort and sort
N = 50000;
a = floor(rand(N,1)*N/2)+1;
tic,[b,I] = csort(a,1,floor(N/2)+1);toc
tic,[b1,I1] = sort(a);toc

## CROSS-REFERENCE INFORMATION

This function calls:
 error Display message and abort function.
This function is called by:
 bincount 1-dimensional Bin Count

## SOURCE CODE

```001 function [b,I] = csort(a,amin,amax,chk)
002 %CSORT Counting sorting
003 %
004 % CALL [b,I] = csort(a,amin,amax)
005 %
006 % b    = sorted vector
007 % I    = index vector defined by b = a(I);
008 % a    = vector of integers to sort (length N).
009 % amin = minimum value of a (default min(a)).
010 % amax = maximum value of a (default max(a)).
011 %
012 % CSORT assumes that each of the N input elements is an integer. Let K
013 % denote the range of the integers. When K = O(N) the sorting
014 % runs in O(N) time.
015 %
016 % Example: % Compare csort and sort
017 %  N = 50000;
018 %  a = floor(rand(N,1)*N/2)+1;
019 %  tic,[b,I] = csort(a,1,floor(N/2)+1);toc
020 %  tic,[b1,I1] = sort(a);toc
021 %
023
024
025 %Tested on: matlab 5.3
026 % History:
027 % by pab 15.08.2001
028
029
030 error(nargchk(1,4,nargin))
031 disp('This function is only available as a mex-compiled function.')
032 error('Compile csort.c by using mex -O csort.c and try again.')
033
034```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003