This is a static copy of a profile report

Home

sortrows (22 calls, 0.000 sec)
Generated 05-Nov-2014 07:52:33 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/datafun/sortrows.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
sort_natfunction22
Lines where the most time was spent
No measurable time spent in this function

Line NumberCodeCallsTotal Time% TimeTime Plot
99
if isequal(size(x),[0 0])
220 s0%
96
y = x(ndx,:);
220 s0%
73
ndx = sortrowsc(x_sub, col);
220 s0%
70
if isreal(x) && ~isspa...
220 s0%
55
col = 1:n;
220 s0%
All other lines  0 s0%
Totals  0 s0% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function102
Non-code lines (comments, blank lines)65
Code lines (lines that can run)37
Code lines that did run10
Code lines that did not run27
Coverage (did run/can run)27.03 %
Function listing
   time   calls  line
1 function [y,ndx] = sortrows(x,col)
2 %SORTROWS Sort rows in ascending order.
3 % Y = SORTROWS(X) sorts the rows of the matrix X in ascending order as a
4 % group. X is a 2-D numeric or char matrix. For a char matrix containing
5 % strings in each row, this is the familiar dictionary sort. When X is
6 % complex, the elements are sorted by ABS(X). Complex matches are further
7 % sorted by ANGLE(X). X can be any numeric or char class. Y is the same
8 % size and class as X.
9 %
10 % SORTROWS(X,COL) sorts the matrix based on the columns specified in the
11 % vector COL. If an element of COL is positive, the corresponding column
12 % in X will be sorted in ascending order; if an element of COL is negative,
13 % the corresponding column in X will be sorted in descending order. For
14 % example, SORTROWS(X,[2 -3]) sorts the rows of X first in ascending order
15 % for the second column, and then by descending order for the third
16 % column.
17 %
18 % [Y,I] = SORTROWS(X) and [Y,I] = SORTROWS(X,COL) also returns an index
19 % matrix I such that Y = X(I,:).
20 %
21 % Notes
22 % -----
23 % SORTROWS uses a stable version of quicksort. NaN values are sorted
24 % as if they are higher than all other values, including +Inf.
25 %
26 % Class support for input X:
27 % numeric, logical, char
28 %
29 % See also SORT, ISSORTED.
30
31 % Copyright 1984-2011 The MathWorks, Inc.
32 % $Revision: 1.19.4.13 $ $Date: 2011/05/17 02:22:23 $
33
34 % I/O details
35 % -----------
36 % X - 2-D matrix of any type for which SORT works.
37 %
38 % COL - Vector. Must contain integers whose magnitude is between 1 and size(X,2).
39 % May be any numeric class.
40 %
41 % Y - 2-D matrix. Same size and class as X.
42 %
43 % NDX - Column vector of size M-by-1, where M is size(X,1). Double.
44 % Contains row indices into X.
45
22 46 error(nargchk(1,2,nargin,'struct'))
22 47 if ~ismatrix(x)
48 error(message('MATLAB:sortrows:inputDimensionMismatch'));
49 end
50
22 51 n = size(x,2);
52
22 53 if nargin < 2
22 54 x_sub = x;
22 55 col = 1:n;
56 else
57 if isnumeric(col)
58 col = double(col);
59 else
60 error(message('MATLAB:sortrows:COLnotNumeric'));
61 end
62 if ( ~isreal(col) || numel(col) ~= length(col) ||...
63 any(floor(col) ~= col) || any(abs(col) > n) || any(col == 0) )
64 error(message('MATLAB:sortrows:COLmismatchX'));
65 end
66
67 x_sub = x(:, abs(col));
68 end
69
22 70 if isreal(x) && ~issparse(x) && n > 3
71 % Call MEX-file to do the hard work for non-sparse real
72 % and character arrays. Only called if at least 4 elements per row.
22 73 ndx = sortrowsc(x_sub, col);
74
75 elseif isnumeric(x) && ~isreal(x) && ~issparse(x)
76 % sort_complex implements the specified behavior of using ABS(X) as
77 % the primary key and ANGLE(X) as the secondary key.
78 ndx = sort_complex(x_sub, col);
79
80 elseif issparse(x)
81 % We'll use the old sortrows algorithm for sparse.
82 ndx = sort_sparse(x_sub, col);
83
84 else
85 % For sparse arrays, cell arrays, and anything else for which the
86 % sortrows worked MATLAB 6.0 or earlier, use the old MATLAB 6.0
87 % algorithm. Also called if 3 or fewer elements per row.
88 if iscell(x)
89 ndx = sort_cell_back_to_front(x_sub, col);
90 else
91 ndx = sort_back_to_front(x_sub, col);
92 end
93 end
94
95 % Rearrange input rows according to the output of the sort algorithm.
22 96 y = x(ndx,:);
97
98 % If input is 0-by-0, make sure output is also 0-by-0.
22 99 if isequal(size(x),[0 0])
100 y = reshape(y,[0 0]);
101 ndx = reshape(ndx,[0 0]);
102 end

Other subfunctions in this file are not included in this listing.