This is a static copy of a profile report

Home

strmatch (86145 calls, 29.381 sec)
Generated 05-Nov-2014 07:52:57 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/strfun/strmatch.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
cell.strmatchfunction32774
bwmorphfunction53371
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
81
if (strs(outer,inner) ~= str(i...
19419955.397 s18.4%
80
for inner = 1:len
13447154.056 s13.8%
82
mask(outer) = false;
12620134.026 s13.7%
86
end 
13447153.715 s12.6%
83
break; % exit matching this ro...
12620133.625 s12.3%
All other lines  8.562 s29.1%
Totals  29.381 s100% 
Children (called functions)
No children
Code Analyzer results
Line numberMessage
61The value assigned here to 'strm' appears to be unused. Consider replacing it by ~.
Coverage results
[ Show coverage for parent directory ]
Total lines in function88
Non-code lines (comments, blank lines)37
Code lines (lines that can run)51
Code lines that did run37
Code lines that did not run14
Coverage (did run/can run)72.55 %
Function listing
   time   calls  line
1 function i = strmatch(str,strs,flag)
2 %STRMATCH Find possible matches for string.
3 % I = STRMATCH(STR, STRARRAY) looks through the rows of the character
4 % array or cell array of strings STRARRAY to find strings that begin
5 % with the string contained in STR, and returns the matching row indices.
6 % Any trailing space characters in STR or STRARRAY are ignored when
7 % matching. STRMATCH is fastest when STRARRAY is a character array.
8 %
9 % I = STRMATCH(STR, STRARRAY, 'exact') compares STR with each row of
10 % STRARRAY, looking for an exact match of the entire strings. Any
11 % trailing space characters in STR or STRARRAY are ignored when matching.
12 %
13 % Examples
14 % i = strmatch('max',strvcat('max','minimax','maximum'))
15 % returns i = [1; 3] since rows 1 and 3 begin with 'max', and
16 % i = strmatch('max',strvcat('max','minimax','maximum'),'exact')
17 % returns i = 1, since only row 1 matches 'max' exactly.
18 %
19 % STRMATCH will be removed in a future release. Use STRNCMP instead.
20 %
21 % See also STRFIND, STRVCAT, STRCMP, STRNCMP, REGEXP.
22
23 % Mark W. Reichelt, 8-29-94
24 % Copyright 1984-2010 The MathWorks, Inc.
25 % $Revision: 1.21.4.14 $ $Date: 2011/02/15 00:54:11 $
26
27 % The cell array implementation is in @cell/strmatch.m
28
0.32 86145 29 if( nargin < 2 )
30 error(nargchk(2,3,nargin,'struct'));
31 end
32
0.21 86145 33 [m,n] = size(strs);
0.27 86145 34 len = numel(str);
35
0.27 86145 36 if (nargin==3)
1721 37 exactMatch = true;
1721 38 if ~ischar(flag)
39 warning(message('MATLAB:strmatch:InvalidFlagType'));
0.01 1721 40 elseif ~strcmpi(flag,'exact')
41 warning(message('MATLAB:strmatch:InvalidFlag', flag, flag));
42 end
0.21 84424 43 else
0.27 84424 44 exactMatch = false;
0.22 84424 45 end
46
47 % Special treatment for empty STR or STRS to avoid
48 % warnings and error below
0.22 86145 49 if len==0
50 str = reshape(str,1,len);
51 end
0.21 86145 52 if n==0
53 strs = reshape(strs,max(m,1),n);
54 [m,n] = size(strs);
55 end
56
0.27 86145 57 if len > n
58 i = [];
0.22 86145 59 else
0.27 86145 60 if exactMatch && len < n % if 'exact' flag, pad str with blanks or nulls
0.02 1721 61 [strm,strn] = size(str);
1721 62 if strn ~= len
63 error(message('MATLAB:strmatch:InvalidShape'));
1721 64 else
65 % Use nulls if anything in the last column is a null.
0.02 1721 66 null = char(0);
1721 67 space = ' ';
0.05 1721 68 if ~isempty(strs) && any(strs(:,end)==null),
69 str = [str null(ones(1,n-len))];
1721 70 else
0.05 1721 71 str = [str space(ones(1,n-len))];
0.01 1721 72 end
1721 73 len = n;
1721 74 end
0.01 1721 75 end
76
0.75 86145 77 mask = true(m,1);
78 % walk from end of strs array and search for row starting with str.
0.40 86145 79 for outer = 1:m
4.06 1344715 80 for inner = 1:len
5.40 1941995 81 if (strs(outer,inner) ~= str(inner))
4.03 1262013 82 mask(outer) = false;
3.63 1262013 83 break; % exit matching this row in strs with str.
84 end
1.98 679982 85 end
3.72 1344715 86 end
0.53 86145 87 i = find(mask);
0.45 86145 88 end