This is a static copy of a profile report

Home

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

Parents (calling functions)

Function NameFunction TypeCalls
graphics\private\cloM-function1
delete_generator_connections_2M-function1
delete_generator_connectionsM-function1
closeM-function87
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
69
c = unique(a);
670.031 s33.3%
110
tf = ~(ismember(a,b));
20.016 s16.7%
29
flag = [];
900.000 s0.2%
20
nIn = nargin;
900.000 s0.0%
46
numelB = length(b);
900.000 s0.0%
Other lines & overhead  0.047 s49.7%
Totals  0.094 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
uniqueM-function690.016 s16.7%
ismemberM-function20.016 s16.7%
Self time (built-ins, overhead, etc.)  0.063 s66.7%
Totals  0.094 s100% 
M-Lint results
No M-Lint messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in file199
Non-code lines (comments, blank lines)77
Code lines (lines that can run)122
Code lines that did run48
Code lines that did not run74
Coverage (did run/can run)39.34 %
Function listing
   time   calls  line
1 function [c,ia] = setdiff(a,b,flag)
2 %SETDIFF Set difference.
3 % SETDIFF(A,B) when A and B are vectors returns the values
4 % in A that are not in B. The result will be sorted. A and B
5 % can be cell arrays of strings.
6 %
7 % SETDIFF(A,B,'rows') when A are B are matrices with the same
8 % number of columns returns the rows from A that are not in B.
9 %
10 % [C,I] = SETDIFF(...) also returns an index vector I such that
11 % C = A(I) (or C = A(I,:)).
12 %
13 % See also UNIQUE, UNION, INTERSECT, SETXOR, ISMEMBER.
14
15 % Copyright 1984-2004 The MathWorks, Inc.
16 % $Revision: 1.22.4.4 $ $Date: 2005/03/07 17:32:54 $
17
18 % Cell array implementation in @cell/setdiff.m
19
< 0.01 90 20 nIn = nargin;
21
90 22 if nIn < 2
23 error('MATLAB:SETDIFF:NotEnoughInputs', 'Not enough input arguments.');
90 24 elseif nIn > 3
25 error('MATLAB:SETDIFF:TooManyInputs', 'Too many input arguments.');
26 end
27
< 0.01 90 28 if nIn == 2
< 0.01 90 29 flag = [];
< 0.01 90 30 end
31
90 32 isrows = strcmpi(flag,'rows');
33
< 0.01 90 34 rowsA = size(a,1);
< 0.01 90 35 colsA = size(a,2);
< 0.01 90 36 rowsB = size(b,1);
< 0.01 90 37 colsB = size(b,2);
38
90 39 rowvec = ~((rowsA > 1 && colsB <= 1) || (rowsB > 1 && colsA <= 1) || isrows);
40
< 0.01 90 41 nOut = nargout;
42
90 43 if isempty(flag)
44
< 0.01 90 45 numelA = length(a);
< 0.01 90 46 numelB = length(b);
47
90 48 if numel(a)~=numelA || numel(b)~=numelB
49 error('MATLAB:SETDIFF:AandBvectorsOrRowsFlag', ...
50 'A and B must be vectors or ''rows'' must be specified.');
51 end
52
53 % Handle empty arrays.
54
90 55 if (numelA == 0)
56 % Predefine outputs to be of the correct type.
21 57 c = a([]);
< 0.01 21 58 ia = [];
59 % Ambiguous if no way to determine whether to return a row or column.
< 0.01 21 60 ambiguous = (rowsA==0 && colsA==0) && ...
61 ((rowsB==0 && colsB==0) || numelB == 1);
21 62 if ~ambiguous
21 63 c = reshape(c,0,1);
21 64 ia = reshape(ia,0,1);
21 65 end
69 66 elseif (numelB == 0)
67 % If B is empty, invoke UNIQUE to remove duplicates from A.
67 68 if nOut <= 1
0.03 67 69 c = unique(a);
70 else
71 [c,ia] = unique(a);
72 end
67 73 return
74
75 % Handle scalar: one element. Scalar A done only.
76 % Scalar B handled within ISMEMBER and general implementation.
77
2 78 elseif (numelA == 1)
79 if ~ismember(a,b,flag)
80 c = a;
81 ia = 1;
82 else
83 c = [];
84 ia = [];
85 end
86 return
87
88 % General handling.
89
2 90 else
91
92 % Convert to columns.
2 93 a = a(:);
2 94 b = b(:);
95
96 % Convert to double arrays, which sort faster than other types.
97
2 98 whichclass = class(a);
2 99 isdouble = strcmp(whichclass,'double');
100
2 101 if ~isdouble
102 a = double(a);
103 end
104
2 105 if ~strcmp(class(b),'double')
106 b = double(b);
107 end
108
109 % Call ISMEMBER to determine list of non-matching elements of A.
0.02 2 110 tf = ~(ismember(a,b));
2 111 c = a(tf);
112
113 % Call UNIQUE to remove duplicates from list of non-matches.
2 114 if nargout <= 1
2 115 c = unique(c);
116 else
117 [c,ndx] = unique(c);
118
119 % Find indices by using TF and NDX.
120 where = find(tf);
121 ia = where(ndx);
122 end
123
124 % Re-convert to correct output data type using FEVAL.
2 125 if ~isdouble
126 c = feval(whichclass,c);
127 end
2 128 end
129
130 % If row vector, return as row vector.
23 131 if rowvec
23 132 c = c.';
23 133 if nOut > 1
134 ia = ia.';
135 end
23 136 end
137
138 else % 'rows' case
139 if ~isrows
140 error('MATLAB:SETDIFF:UnknownFlag', 'Unknown flag.');
141 end
142
143 % Automatically pad strings with spaces
144 if ischar(a) && ischar(b)
145 if colsA > colsB
146 b = [b repmat(' ',rowsB,colsA-colsB)];
147 elseif colsA < colsB
148 a = [a repmat(' ',rowsA,colsB-colsA)];
149 colsA = colsB;
150 end
151 elseif colsA ~= colsB
152 error('MATLAB:SETDIFF:AandBColnumAgree',...
153 'A and B must have the same number of columns.');
154 end
155
156 % Handle empty arrays
157 if rowsA == 0
158 c = zeros(rowsA,colsA);
159 ia = [];
160 elseif colsA == 0 && rowsA > 0
161 c = zeros(1,0);
162 ia = rowsA;
163 % General handling
164 else
165 % Remove duplicates from A; get indices only if needed
166 if nOut > 1
167 [a,ia] = unique(a,flag);
168 else
169 a = unique(a,flag);
170 end
171
172 % Create sorted list of unique A and B; want non-matching entries
173 [c,ndx] = sortrows([a;b]);
174 [rowsC,colsC] = size(c);
175 if rowsC > 1 && colsC ~= 0
176 % d indicates the location of non-matching entries
177 d = c(1:rowsC-1,:) ~= c(2:rowsC,:);
178 else
179 d = zeros(rowsC-1,0);
180 end
181 d = any(d,2);
182 d(rowsC,1) = 1; % Final entry always included.
183
184 % d = 1 now for any unmatched entry of A or of B.
185 n = size(a,1);
186 d = d & ndx <= n; % Now find only the ones in A.
187
188 c = c(d,:);
189
190 if nOut > 1
191 ia = ia(ndx(d));
192 end
193 end
194 end
195
196 % Automatically deblank strings
23 197 if ischar(a)
198 c = deblank(c);
199 end