gusucode.com > datatypes 工具箱matlab源码程序 > datatypes/@timetable/sortrows.m

    function [b,idx] = sortrows(a,vars,sortMode)
%SORTROWS Sort rows of a timetable.
%   B = SORTROWS(A) returns a copy of the timetable A, with the rows sorted
%   in ascending order by time.
%
%   B = SORTROWS(A,VARS) sorts the rows in A by the variables specified by VARS.
%   VARS is a positive integer, a vector of positive integers, a variable name,
%   a cell array containing one or more variable names, or a logical vector. The
%   rows in B are sorted first by the first variable, next by the second
%   variable, and so on.  Each variable in A must be a valid input to SORT, or,
%   if the variable has multiple columns, to the MATLAB SORTROWS function or to
%   its own SORTROWS method.
%
%   VARS may also contain a mix of positive and negative integers.  If an
%   element of VARS is positive, the corresponding variable in A will be sorted
%   in ascending order; if an element of VARS is negative, the corresponding
%   variable in A will be sorted in descending order.  These signs are ignored
%   if you provide the MODE input described below.
%
%   B = SORTROWS(A,'Time') sorts the rows in A by time, the default behavior.
%
%   B = SORTROWS(A,VARS,MODE) sorts A in the direction(s) specified by MODE.
%   When MODE is 'ascend' (the default) or 'descend', SORTROWS sorts A in
%   ascending or descending order, respectively, for all variables specified
%   by VARS.  MODE may also be a cell array containing the character
%   vectors 'ascend' or 'descend' to specify a different direction for each
%   variable specified by VARS.  Specify VARS as 1:SIZE(A,2) to sort using
%   all variables.
%
%   [B,IDX] = SORTROWS(A, ...) also returns an index vector IDX such that
%   B = A(IDX,:).
%
%   See also ISSORTED, UNIQUE.

%   Copyright 2016 The MathWorks, Inc.

if nargin < 2
    vars = a.metaDim.labels(1);
end

if nargin < 3
    [b,idx] = sortrows@tabular(a,vars);
else
    [b,idx] = sortrows@tabular(a,vars,sortMode);
end