time | Calls | line |
---|
| | 155 | function [lia,locb] = ismemberR2012a(a,b,options)
|
| | 156 | % 'R2012a' flag implementation
|
| | 157 |
|
| | 158 | % Error check flag
|
0.001 | 20 | 159 | if nargin == 2
|
< 0.001 | 20 | 160 | byrow = false;
|
| | 161 | else
|
| | 162 | byrow = options > 0;
|
< 0.001 | 20 | 163 | end
|
| | 164 |
|
< 0.001 | 20 | 165 | doBuiltinTypes = true;
|
| | 166 | % Check that one of A and B is double if A and B are non-homogeneous. Do a
|
| | 167 | % separate check if A is a heterogeneous object and only allow a B
|
| | 168 | % that is of the same root class.
|
0.002 | 20 | 169 | if ~(isa(a,'handle.handle') || isa(b,'handle.handle'))
|
< 0.001 | 20 | 170 | if ~strcmpi(class(a),class(b))
|
< 0.001 | 11 | 171 | if isa(a,'matlab.mixin.Heterogeneous') && isa(b,'matlab.mixin.Heterogeneous')
|
| | 172 | rootClassA = meta.internal.findHeterogeneousRootClass(a);
|
| | 173 | if isempty(rootClassA) || ~isa(b,rootClassA.Name)
|
| | 174 | error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
|
| | 175 | end
|
| | 176 | doBuiltinTypes = false;
|
< 0.001 | 11 | 177 | elseif ~(strcmpi(class(a),'double') || strcmpi(class(b),'double'))
|
| | 178 | error(message('MATLAB:ISMEMBER:InvalidInputsDataType',class(a),class(b)));
|
| | 179 | end
|
< 0.001 | 11 | 180 | end
|
< 0.001 | 20 | 181 | end
|
| | 182 |
|
< 0.001 | 20 | 183 | if ~byrow
|
0.002 | 20 | 184 | if ~(isa(a,'opaque') || isa(b,'opaque')) && doBuiltinTypes
|
| | 185 | % Builtin types
|
< 0.001 | 9 | 186 | if nargout > 1
|
0.002 | 4 | 187 | [lia,locb] = ismemberBuiltinTypes(a,b);
|
< 0.001 | 5 | 188 | else
|
0.003 | 5 | 189 | lia = ismemberBuiltinTypes(a,b);
|
< 0.001 | 9 | 190 | end
|
< 0.001 | 11 | 191 | else
|
| | 192 | % Handle objects
|
< 0.001 | 11 | 193 | if nargout > 1
|
0.003 | 1 | 194 | [lia,locb] = ismemberClassTypes(a,b);
|
< 0.001 | 10 | 195 | else
|
0.026 | 10 | 196 | lia = ismemberClassTypes(a,b);
|
< 0.001 | 11 | 197 | end
|
< 0.001 | 20 | 198 | end
|
| | 199 | else % 'rows' case
|
| | 200 | if ~(ismatrix(a) && ismatrix(b))
|
| | 201 | error(message('MATLAB:ISMEMBER:NotAMatrix'));
|
| | 202 | end
|
| | 203 |
|
| | 204 | [rowsA,colsA] = size(a);
|
| | 205 | [rowsB,colsB] = size(b);
|
| | 206 |
|
| | 207 | % Automatically pad strings with spaces
|
| | 208 | if ischar(a) && ischar(b)
|
| | 209 | b = [b repmat(' ',rowsB,colsA-colsB)];
|
| | 210 | a = [a repmat(' ',rowsA,colsB-colsA)];
|
| | 211 | elseif colsA ~= colsB
|
| | 212 | error(message('MATLAB:ISMEMBER:AandBColnumAgree'));
|
| | 213 | end
|
| | 214 |
|
| | 215 | % Empty check for 'rows'.
|
| | 216 | if rowsA == 0 || rowsB == 0
|
| | 217 | lia = false(rowsA,1);
|
| | 218 | locb = zeros(rowsA,1);
|
| | 219 | return
|
| | 220 | end
|
| | 221 |
|
| | 222 | % General handling for 'rows'.
|
| | 223 |
|
| | 224 | % Duplicates within the sets are eliminated
|
| | 225 | if (rowsA == 1)
|
| | 226 | uA = repmat(a,rowsB,1);
|
| | 227 | d = uA(1:end,:)==b(1:end,:);
|
| | 228 | d = all(d,2);
|
| | 229 | lia = any(d);
|
| | 230 | if nargout > 1
|
| | 231 | if lia
|
| | 232 | locb = find(d, 1, 'first');
|
| | 233 | else
|
| | 234 | locb = 0;
|
| | 235 | end
|
| | 236 | end
|
| | 237 | return;
|
| | 238 | else
|
| | 239 | [uA,~,icA] = unique(a,'rows','sorted');
|
| | 240 | end
|
| | 241 | if nargout <= 1
|
| | 242 | uB = unique(b,'rows','sorted');
|
| | 243 | else
|
| | 244 | [uB,ib] = unique(b,'rows','sorted');
|
| | 245 | end
|
| | 246 |
|
| | 247 | % Sort the unique elements of A and B, duplicate entries are adjacent
|
| | 248 | [sortuAuB,IndSortuAuB] = sortrows([uA;uB]);
|
| | 249 |
|
| | 250 | % Find matching entries
|
| | 251 | d = sortuAuB(1:end-1,:)==sortuAuB(2:end,:); % d indicates matching entries
|
| | 252 | d = all(d,2); % Finds the index of matching entries
|
| | 253 | ndx1 = IndSortuAuB(d); % NDX1 are locations of repeats in C
|
| | 254 |
|
| | 255 | if nargout <= 1
|
| | 256 | lia = ismemberBuiltinTypes(icA,ndx1); % Find repeats among original list
|
| | 257 | else
|
| | 258 | szuA = size(uA,1);
|
| | 259 | [lia,locb] = ismemberBuiltinTypes(icA,ndx1); % Find locb by using given indices
|
| | 260 | d = find(d);
|
| | 261 | newd = d(locb(lia)); % NEWD is D for non-unique A
|
| | 262 | where = ib(IndSortuAuB(newd+1)-szuA); % Index values of uB through UNIQUE
|
| | 263 | locb(lia) = where; % Return first or last occurrence of A within B
|
| | 264 | end
|
< 0.001 | 20 | 265 | end
|
< 0.001 | 20 | 266 | end
|
Other subfunctions in this file are not included in this listing.