This is a static copy of a profile reportHome
strmatch (7422 calls, 2.044 sec)
Generated 05-Aug-2011 13:01:15 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/strfun/strmatch.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
83 | if (strs(outer,inner) ~= str(i... | 613193 | 0.459 s | 22.5% |  |
84 | mask(outer) = false; | 457008 | 0.372 s | 18.2% |  |
82 | for inner = 1:len | 463950 | 0.350 s | 17.1% |  |
85 | break; % exit matching this ro... | 457008 | 0.317 s | 15.5% |  |
88 | end | 463950 | 0.186 s | 9.1% |  |
All other lines | | | 0.361 s | 17.6% |  |
Totals | | | 2.044 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
Line number | Message |
63 | The value assigned here to 'strm' appears to be unused. Consider replacing it by ~. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 90 |
Non-code lines (comments, blank lines) | 39 |
Code lines (lines that can run) | 51 |
Code lines that did run | 38 |
Code lines that did not run | 13 |
Coverage (did run/can run) | 74.51 % |
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.13 $ $Date: 2010/11/17 11:30:02 $
26
27 % The cell array implementation is in @cell/strmatch.m
28
0.01 7422 29 if( nargin < 2 )
30 error(nargchk(2,3,nargin,'struct'));
31 end
32
0.01 7422 33 [m,n] = size(strs);
0.02 7422 34 len = numel(str);
35
7422 36 if (nargin==3)
502 37 exactMatch = true;
502 38 if ~ischar(flag)
39 warning('MATLAB:strmatch:InvalidFlagType', ...
40 'The third argument to STRMATCH is not valid and will not be recognized in \na future version of MATLAB. Use string ''exact'' instead.');
502 41 elseif ~strcmpi(flag,'exact')
42 warning('MATLAB:strmatch:InvalidFlag', ...
43 'Use flag ''exact'' in place of ''%s''. Flag ''%s'' \nis not valid and will not be recognized in a future version of MATLAB.', flag, flag);
44 end
0.01 6920 45 else
6920 46 exactMatch = false;
0.01 6920 47 end
48
49 % Special treatment for empty STR or STRS to avoid
50 % warnings and error below
7422 51 if len==0
52 str = reshape(str,1,len);
53 end
7422 54 if n==0
55 strs = reshape(strs,max(m,1),n);
56 [m,n] = size(strs);
57 end
58
7422 59 if len > n
198 60 i = [];
0.02 7224 61 else
0.01 7224 62 if exactMatch && len < n % if 'exact' flag, pad str with blanks or nulls
200 63 [strm,strn] = size(str);
200 64 if strn ~= len
65 error(message('MATLAB:strmatch:InvalidShape'));
200 66 else
67 % Use nulls if anything in the last column is a null.
200 68 null = char(0);
200 69 space = ' ';
200 70 if ~isempty(strs) && any(strs(:,end)==null),
71 str = [str null(ones(1,n-len))];
200 72 else
200 73 str = [str space(ones(1,n-len))];
200 74 end
200 75 len = n;
200 76 end
200 77 end
78
0.02 7224 79 mask = true(m,1);
80 % walk from end of strs array and search for row starting with str.
0.01 7224 81 for outer = 1:m
0.35 463950 82 for inner = 1:len
0.46 613193 83 if (strs(outer,inner) ~= str(inner))
0.37 457008 84 mask(outer) = false;
0.32 457008 85 break; % exit matching this row in strs with str.
86 end
0.08 156185 87 end
0.19 463950 88 end
0.02 7224 89 i = find(mask);
0.03 7224 90 end