This is a static copy of a profile reportHome
sort_nat (22 calls, 0.220 sec)
Generated 05-Nov-2014 07:52:33 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/sort_nat/sort_nat.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
ml_ls | function | 20 |
ml_dir | function | 2 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
62 | num_val(i,z(i,:)) = sscanf(spr... | 2019 | 0.080 s | 36.4% |  |
90 | [unused,index] = sortrows(comp... | 22 | 0.030 s | 13.6% |  |
63 | num_dig(i,z(i,:)) = last{i} - ... | 2019 | 0.030 s | 13.6% |  |
46 | c2 = regexprep(c,'\d+','0'); | 22 | 0.030 s | 13.6% |  |
64 | end | 2019 | 0.020 s | 9.1% |  |
All other lines | | | 0.030 s | 13.6% |  |
Totals | | | 0.220 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
sortrows | function | 22 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.220 s | 100.0% |  |
Totals | | | 0.220 s | 100% | |
Code Analyzer results
Line number | Message |
90 | The value assigned here to 'unused' appears to be unused. Consider replacing it by ~. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 95 |
Non-code lines (comments, blank lines) | 58 |
Code lines (lines that can run) | 37 |
Code lines that did run | 33 |
Code lines that did not run | 4 |
Coverage (did run/can run) | 89.19 % |
Function listing
time calls line
1 function [cs,index] = sort_nat(c,mode)
2 %sort_nat: Natural order sort of cell array of strings.
3 % usage: [S,INDEX] = sort_nat(C)
4 %
5 % where,
6 % C is a cell array (vector) of strings to be sorted.
7 % S is C, sorted in natural order.
8 % INDEX is the sort order such that S = C(INDEX);
9 %
10 % Natural order sorting sorts strings containing digits in a way such that
11 % the numerical value of the digits is taken into account. It is
12 % especially useful for sorting file names containing index numbers with
13 % different numbers of digits. Often, people will use leading zeros to get
14 % the right sort order, but with this function you don't have to do that.
15 % For example, if C = {'file1.txt','file2.txt','file10.txt'}, a normal sort
16 % will give you
17 %
18 % {'file1.txt' 'file10.txt' 'file2.txt'}
19 %
20 % whereas, sort_nat will give you
21 %
22 % {'file1.txt' 'file2.txt' 'file10.txt'}
23 %
24 % See also: sort
25
26 % Version: 1.4, 22 January 2011
27 % Author: Douglas M. Schwarz
28 % Email: dmschwarz=ieee*org, dmschwarz=urgrad*rochester*edu
29 % Real_email = regexprep(Email,{'=','*'},{'@','.'})
30
31
32 % Set default value for mode if necessary.
22 33 if nargin < 2
22 34 mode = 'ascend';
22 35 end
36
37 % Make sure mode is either 'ascend' or 'descend'.
22 38 modes = strcmpi(mode,{'ascend','descend'});
22 39 is_descend = modes(2);
22 40 if ~any(modes)
41 error('sort_nat:sortDirection',...
42 'sorting direction must be ''ascend'' or ''descend''.')
43 end
44
45 % Replace runs of digits with '0'.
0.03 22 46 c2 = regexprep(c,'\d+','0');
47
48 % Compute char version of c2 and locations of zeros.
22 49 s1 = char(c2);
22 50 z = s1 == '0';
51
52 % Extract the runs of digits and their start and end indices.
0.02 22 53 [digruns,first,last] = regexp(c,'\d+','match','start','end');
54
55 % Create matrix of numerical values of runs of digits and a matrix of the
56 % number of digits in each run.
22 57 num_str = length(c);
22 58 max_len = size(s1,2);
22 59 num_val = NaN(num_str,max_len);
22 60 num_dig = NaN(num_str,max_len);
22 61 for i = 1:num_str
0.08 2019 62 num_val(i,z(i,:)) = sscanf(sprintf('%s ',digruns{i}{:}),'%f');
0.03 2019 63 num_dig(i,z(i,:)) = last{i} - first{i} + 1;
0.02 2019 64 end
65
66 % Find columns that have at least one non-NaN. Make sure activecols is a
67 % 1-by-n vector even if n = 0.
0.01 22 68 activecols = reshape(find(~all(isnan(num_val))),1,[]);
22 69 n = length(activecols);
70
71 % Compute which columns in the composite matrix get the numbers.
22 72 numcols = activecols + (1:2:2*n);
73
74 % Compute which columns in the composite matrix get the number of digits.
22 75 ndigcols = numcols + 1;
76
77 % Compute which columns in the composite matrix get chars.
22 78 charcols = true(1,max_len + 2*n);
22 79 charcols(numcols) = false;
22 80 charcols(ndigcols) = false;
81
82 % Create and fill composite matrix, comp.
22 83 comp = zeros(num_str,max_len + 2*n);
22 84 comp(:,charcols) = double(s1);
22 85 comp(:,numcols) = num_val(:,activecols);
22 86 comp(:,ndigcols) = num_dig(:,activecols);
87
88 % Sort rows of composite matrix and use index to sort c in ascending or
89 % descending order, depending on mode.
0.03 22 90 [unused,index] = sortrows(comp);
22 91 if is_descend
92 index = index(end:-1:1);
93 end
22 94 index = reshape(index,size(c));
22 95 cs = c(index);