www.gusucode.com > datafun 工具箱matlab源码程序 > datafun/sort.m

    %SORT   Sort in ascending or descending order.
%   For vectors, SORT(X) sorts the elements of X in ascending order.
%   For matrices, SORT(X) sorts each column of X in ascending order.
%   For N-D arrays, SORT(X) sorts along the first non-singleton
%   dimension of X. When X is a cell array of strings, SORT(X) sorts
%   the strings in ASCII dictionary order.
%
%   Y = SORT(X,DIM,MODE)
%   has two optional parameters.  
%   DIM selects a dimension along which to sort.
%   MODE selects the direction of the sort
%      'ascend' results in ascending order
%      'descend' results in descending order
%   The result is in Y which has the same shape and type as X.
%
%   [Y,I] = SORT(X,DIM,MODE) also returns an index matrix I.
%   If X is a vector, then Y = X(I).  
%   If X is an m-by-n matrix and DIM=1, then
%       for j = 1:n, Y(:,j) = X(I(:,j),j); end
%
%   When X is complex, the elements are sorted by ABS(X).  Complex
%   matches are further sorted by ANGLE(X).
%
%   When more than one element has the same value, the order of the
%   elements is preserved in the sorted result and the indices 
%   relating to equal elements will be ascending.
%
%   Example: 
%       X = [3 7 5; 0 4 2]
%       sort(X,1)
%       sort(X,2)
%
%   See also ISSORTED, SORTROWS, MIN, MAX, MEAN, MEDIAN, UNIQUE.

%   Copyright 1984-2015 The MathWorks, Inc.
%   Built-in function.