This is a static copy of a profile report

Home

cell.ismember (40 calls, 0.055 sec)
Generated 05-Aug-2011 13:00:27 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/ops/@cell/ismember.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
imagesci/private/writepngfunction40
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
77
tfstep = ismember(char(a),char...
400.033 s60.0%
50
lS = cellfun('length',s);
400.011 s20.0%
27
if ~((ischar(a) || iscellstr(a...
400.011 s20.0%
87
if nargout > 1
400 s0%
85
tf = reshape(tf,size(a));
400 s0%
All other lines  0.000 s0.0%
Totals  0.055 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismemberfunction400.033 s60.0%
iscellstrfunction800.011 s20.0%
Self time (built-ins, overhead, etc.)  0.011 s20.0%
Totals  0.055 s100% 
Code Analyzer results
Line numberMessage
1Input argument 'flag' might be unused. If this is OK, consider replacing it by ~.
57Variable 'memS' might be set by a nonlogical operator.
Coverage results
[ Show coverage for parent directory ]
Total lines in function89
Non-code lines (comments, blank lines)31
Code lines (lines that can run)58
Code lines that did run33
Code lines that did not run25
Coverage (did run/can run)56.90 %
Function listing
   time   calls  line
1 function [tf,loc] = ismember(a,s,flag)
2 %ISMEMBER True for set member for cell array of strings.
3 % ISMEMBER(A,S) for the cell array of strings A returns a logical array of
4 % the same size as A containing 1 where the elements of A are in the set S
5 % and 0 otherwise.
6 %
7 % [TF,LOC] = ISMEMBER(...) also returns an index array LOC containing the
8 % highest absolute index in S for each element in A which is a member of S
9 % and 0 if there is no such index.
10 %
11 % See also UNIQUE, INTERSECT, SETDIFF, SETXOR, UNION.
12
13 % Copyright 1984-2008 The MathWorks, Inc.
14 % $Revision: 1.10.4.9 $ $Date: 2008/02/29 12:46:02 $
15
16
17 % handle input
40 18 nIn = nargin;
40 19 if nIn < 2
20 error('MATLAB:ISMEMBER:NumberOfInputs','Not enough input arguments.');
40 21 elseif nIn == 3
22 warning('MATLAB:ISMEMBER:RowsFlagIgnored',...
23 'Third argument is ignored for cell arrays.');
40 24 elseif nIn > 3
25 error('MATLAB:ISMEMBER:NumberOfInputs','Too many input arguments.');
26 end
0.01 40 27 if ~((ischar(a) || iscellstr(a)) && (ischar(s) || iscellstr(s)))
28 error('MATLAB:ISMEMBER:InputClass','Input must be cell arrays of strings.')
29 end
30
31 % convert input to cell arrays of strings
40 32 if ischar(a), a = cellstr(a); end
40 33 if ischar(s), s = cellstr(s); end
34
35 % handle special empty cases
40 36 if isempty(a) && isempty(s)
37 tf = logical([]); % indefinite result.
38 loc = []; % indefinite result.
39 return
40 40 elseif length(s) == 1 && cellfun('isempty',s)
41 tempTF = cellfun('isempty',a);
42 if any(tempTF(:))
43 tf = tempTF; %in case where s is empty, a is found
44 %in s when a is empty
45 loc = double(tf); %location = 1 since s has only one member
46 return
47 end
48 end
49
0.01 40 50 lS = cellfun('length',s);
40 51 lengthS = length(lS(:));
40 52 memS = max(lS(:)) * lengthS;
53
54 % work in chunks of at most 16Mb
40 55 maxMem = 8e6;
40 56 stepsS = ceil(memS/maxMem);
40 57 if memS
40 58 offset = ceil(lengthS/stepsS);
59 else
60 offset = lengthS;
61 end
62
40 63 lengthA = numel(a);
40 64 tf = false(lengthA,1);
40 65 loc = zeros(lengthA,1);
40 66 chunkEnd = lengthS;
67
40 68 while chunkEnd >0
40 69 chunkStart = max(chunkEnd - offset,1);
40 70 chunk = chunkStart:chunkEnd;
40 71 chunkEnd = chunkStart -1;
72 % Only return required arguments from ISMEMBER.
40 73 if nargout > 1
74 [tfstep,locstep] = ismember(char(a),char(s(chunk)),'rows');
75 loc = max(loc,(locstep + chunkStart - 1).*(locstep > 0));
40 76 else
0.03 40 77 tfstep = ismember(char(a),char(s(chunk)),'rows');
40 78 end
40 79 tf = tf | tfstep;
40 80 if (all(tf))
40 81 break;
82 end
83 end
84
40 85 tf = reshape(tf,size(a));
86
40 87 if nargout > 1
88 loc = reshape(loc,size(a));
89 end