This is a static copy of a profile report

Home

ismember (319146 calls, 12.578 sec)
Generated 15-Mar-2007 12:01:42 using real time.
M-function in file C:\Program Files\MATLAB71\toolbox\matlab\ops\ismember.m
[Copy to new window for comparing multiple runs]

Parents (calling functions)

Function NameFunction TypeCalls
think1M-function1
dom_thoughtM-function17
setdiffM-function2
connect_down_bondM-function3
add_generator_up_QM-function3
legacyM-function283
think3M-function1
intersectM-function8
get_mod_transfer_invM-function318828
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
41
if isempty(flag)
3191462.578 s20.5%
45
tf = false(size(a));
3191461.656 s13.2%
55
return
2559221.313 s10.4%
74
tf(i) = any(a(i)==s(:));   % A...
494570.375 s3.0%
34
flag = [];
3191460.331 s2.6%
Other lines & overhead  6.325 s50.3%
Totals  12.578 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
ismembc2MEX-function80 s0%
ismembcMEX-function1220 s0%
Self time (built-ins, overhead, etc.)  12.578 s100.0%
Totals  12.578 s100% 
M-Lint results
Line numberMessage
117The value assigned here to variable 'junk' might never be used.
180The value assigned here to variable 'colsA' might never be used.
198The value assigned here to variable 'tf' might never be used.
208Use FIND with the new 'first' or 'last' option.
215The value assigned here to variable 'am' might never be used.
Coverage results
[ Show coverage for parent directory ]
Total lines in file240
Non-code lines (comments, blank lines)82
Code lines (lines that can run)158
Code lines that did run61
Code lines that did not run97
Coverage (did run/can run)38.61 %
Function listing
   time   calls  line
1 function [tf,loc] = ismember(a,s,flag)
2 %ISMEMBER True for set member.
3 % ISMEMBER(A,S) for the array A returns an array of the same size as A
4 % containing 1 where the elements of A are in the set S and 0 otherwise.
5 % A and S can be cell arrays of strings.
6 %
7 % ISMEMBER(A,S,'rows') when A and S are matrices with the same
8 % number of columns returns a vector containing 1 where the rows of
9 % A are also rows of S and 0 otherwise.
10 %
11 % [TF,LOC] = ISMEMBER(...) also returns an index array LOC containing the
12 % highest absolute index in S for each element in A which is a member of S
13 % and 0 if there is no such index.
14 %
15 % Class support for inputs A,S:
16 % float: double, single
17 %
18 % See also UNIQUE, INTERSECT, SETDIFF, SETXOR, UNION.
19
20 % Copyright 1984-2004 The MathWorks, Inc.
21 % $Revision: 1.23.4.5 $ $Date: 2004/12/06 16:35:38 $
22
23 % Cell array implementation in @cell/ismember.m
24
0.03 319146 25 nIn = nargin;
26
0.28 319146 27 if nIn < 2
28 error('MATLAB:ISMEMBER:NotEnoughInputs', 'Not enough input arguments.');
0.23 319146 29 elseif nIn > 3
30 error('MATLAB:ISMEMBER:TooManyInputs', 'Too many input arguments.');
31 end
32
< 0.01 319146 33 if nIn == 2
0.33 319146 34 flag = [];
< 0.01 319146 35 end
36
< 0.01 319146 37 numelA = numel(a);
0.02 319146 38 numelS = numel(s);
0.01 319146 39 nOut = nargout;
40
2.58 319146 41 if isempty(flag)
42
43 % Initialize types and sizes.
44
1.66 319146 45 tf = false(size(a));
46
0.30 319146 47 if nOut > 1
8 48 loc = zeros(size(a));
8 49 end
50
51 % Handle empty arrays and scalars.
52
0.22 319146 53 if numelA == 0 || numelS <= 1
0.16 269624 54 if (numelA == 0 || numelS == 0)
1.31 255922 55 return
56
57 % Scalar A handled below.
58 % Scalar S: find which elements of A are equal to S.
13702 59 elseif numelS == 1
0.03 13702 60 tf = (a == s);
0.02 13702 61 if nOut > 1
62 % Use DOUBLE to convert logical "1" index to double "1" index.
63 loc = double(tf);
64 end
0.08 13702 65 return
66 end
< 0.01 49522 67 else
68 % General handling.
69 % Use FIND method for very small sizes of the input vector to avoid SORT.
< 0.01 49522 70 scalarcut = 5;
0.02 49522 71 if numelA <= scalarcut
0.05 49392 72 if nOut <= 1
0.09 49392 73 for i=1:numelA
0.38 49457 74 tf(i) = any(a(i)==s(:)); % ANY returns logical.
0.09 49457 75 end
76 else
77 for i=1:numelA
78 found = find(a(i)==s(:)); % FIND returns indices for LOC.
79 if ~isempty(found)
80 tf(i) = 1;
81 loc(i) = found(end);
82 end
83 end
84 end
< 0.01 130 85 else
86 % Use method which sorts list, then performs binary search.
87 % Convert to double for quicker sorting, to full to work in C helper.
130 88 a = double(a);
130 89 if issparse(a)
90 a = full(a);
91 end
92
130 93 s = double(s);
130 94 if issparse(s)
95 s = full(s);
96 end
97
130 98 if (isreal(s))
99 % Find out whether list is presorted before sort
100 % If the list is short enough, SORT will be faster than ISSORTED
101 % If the list is longer, ISSORTED can potentially save time
< 0.01 130 102 checksortcut = 1000;
130 103 if numelS > checksortcut
104 sortedlist = issorted(s(:));
< 0.01 130 105 else
< 0.01 130 106 sortedlist = 0;
< 0.01 130 107 end
130 108 if nOut > 1
8 109 if ~sortedlist
8 110 [s,idx] = sort(s(:));
8 111 end
122 112 elseif ~sortedlist
0.02 122 113 s = sort(s(:));
122 114 end
115 else
116 sortedlist = 0;
117 [junk,idx] = sort(real(s(:)));
118 s = s(idx);
119 end
120
121 % Two C-Helper Functions are used in the code below:
122
123 % ISMEMBC - S must be sorted - Returns logical vector indicating which
124 % elements of A occur in S
125 % ISMEMBC2 - S must be sorted - Returns a vector of the locations of
126 % the elements of A occurring in S. If multiple instances occur,
127 % the last occurrence is returned
128
129 % Check for NaN values - NaN values will be at the end of S,
130 % but may be anywhere in A.
131
130 132 nana = isnan(a(:));
133
130 134 if (any(nana) || isnan(s(numelS)))
135 % If NaNs detected, remove NaNs from the data before calling ISMEMBC.
136 ida = (nana == 0);
137 ids = (isnan(s(:)) == 0);
138 if nOut <= 1
139 ainfn = ismembc(a(ida),s(ids));
140 tf(ida) = ainfn;
141 else
142 loc = ismembc2(a(ida),s(ids));
143 tf(ida) = (loc > 0);
144 loc(ida) = loc;
145 loc(~ida) = 0;
146 end
130 147 else
148 % No NaN values, call ISMEMBC directly.
130 149 if nOut <= 1
122 150 tf = ismembc(a,s);
8 151 else
8 152 loc = ismembc2(a,s);
8 153 tf = (loc > 0);
8 154 end
130 155 end
156
130 157 if nOut > 1 && ~sortedlist
158 % Re-reference loc to original list if it was unsorted
8 159 loc(tf) = idx(loc(tf));
8 160 end
130 161 end
0.33 49522 162 end
163
164 else % 'rows' case
165 if ~strcmpi(flag,'rows')
166 error('MATLAB:ISMEMBER:UnknownFlag', 'Unknown flag.');
167 end
168
169 rowsA = size(a,1);
170 colsA = size(a,2);
171 rowsS = size(s,1);
172 colsS = size(s,2);
173
174 % Automatically pad strings with spaces
175 if ischar(a) && ischar(s),
176 if colsA > colsS
177 s = [s repmat(' ',rowsS,colsA-colsS)];
178 elseif colsA < colsS
179 a = [a repmat(' ',rowsA,colsS-colsA)];
180 colsA = colsS;
181 end
182 elseif colsA ~= colsS && ~isempty(a) && ~isempty(s)
183 error('MATLAB:ISMEMBER:AandBColnumAgree', ...
184 'A and S must have the same number of columns.');
185 end
186
187 % Empty check for 'rows'.
188 if rowsA == 0 || rowsS == 0
189 if (isempty(a) || isempty(s))
190 tf = false(rowsA,1);
191 loc = zeros(rowsA,1);
192 return
193 end
194 end
195
196 % General handling for 'rows'.
197
198 tf = false(rowsA,1);
199
200 % Duplicates within the sets are eliminated
201 if (rowsA == 1)
202 au = repmat(a,rowsS,1);
203 d = au(1:end,:)==s(1:end,:);
204 d = all(d,2);
205 tf = any(d);
206 if nOut > 1
207 if tf
208 loc = max(find(d));
209 else
210 loc = 0;
211 end
212 end
213 return;
214 else
215 [au,am,an] = unique(a,'rows');
216 end
217 if nOut <= 1
218 su = unique(s,'rows');
219 else
220 [su,sm] = unique(s,'rows');
221 end
222
223 % Sort the unique elements of A and S, duplicate entries are adjacent
224 [c,ndx] = sortrows([au;su]);
225
226 % Find matching entries
227 d = c(1:end-1,:)==c(2:end,:); % d indicates matching entries in 2-D
228 d = find(all(d,2)); % Finds the index of matching entries
229 ndx1 = ndx(d); % NDX1 are locations of repeats in C
230
231 if nOut <= 1
232 tf = ismember(an,ndx1); % Find repeats among original list
233 else
234 szau = size(au,1);
235 [tf,loc] = ismember(an,ndx1); % Find loc by using given indices
236 newd = d(loc(tf)); % NEWD is D for non-unique A
237 where = sm(ndx(newd+1)-szau); % Index values of SU through UNIQUE
238 loc(tf) = where; % Return last occurrence of A within S
239 end
240 end