time | Calls | line |
---|
| | 1 | function t = eq(a,b)
|
| | 2 | %EQ Equality for categorical arrays.
|
| | 3 | % A == B does element by element comparisons between the categorical arrays A
|
| | 4 | % and B and returns an array with elements set to logical 1 (TRUE) where the
|
| | 5 | % relation is true and elements set to logical 0 (FALSE) where it is not. A
|
| | 6 | % and B must have compatible sizes. In the simplest cases, they can be the
|
| | 7 | % same size or one can be a scalar. Two inputs have compatible sizes if, for
|
| | 8 | % every dimension, the dimension sizes of the inputs are either the same or
|
| | 9 | % one of them is 1.
|
| | 10 | %
|
| | 11 | % C = EQ(A,B) is called for the syntax 'A == B'.
|
| | 12 | %
|
| | 13 | % If A and B are both ordinal, they must have the same sets of categories,
|
| | 14 | % including their order. If neither A nor B are ordinal, they need not have
|
| | 15 | % the same sets of categories, and the test is performed by comparing the
|
| | 16 | % category names of each pair of elements.
|
| | 17 | %
|
| | 18 | % A == S or S == A, where S is a scalar string or character vector, returns
|
| | 19 | % a logical array the same size as A, containing logical 1 (true) where the
|
| | 20 | % corresponding elements of A are equal to the category S.
|
| | 21 | %
|
| | 22 | % Undefined elements are not comparable to any other categorical values,
|
| | 23 | % including other undefined elements. EQ returns logical 0 (false) where
|
| | 24 | % elements of A or B are undefined.
|
| | 25 | %
|
| | 26 | % See also NE.
|
| | 27 |
|
| | 28 | % Copyright 2006-2020 The MathWorks, Inc.
|
| | 29 |
|
0.643 | 74690 | 30 | [acodes,bcodes] = reconcileCategories(a,b,false);
|
| | 31 |
|
| | 32 | % Undefined elements cannot be equal to anything.
|
0.004 | 74690 | 33 | if isscalar(acodes) % faster scalar case
|
< 0.001 | 5390 | 34 | if acodes > 0 %categorical.undefCode
|
< 0.001 | 5005 | 35 | t = (acodes == bcodes);
|
< 0.001 | 385 | 36 | else
|
< 0.001 | 385 | 37 | t = false(size(bcodes));
|
< 0.001 | 5390 | 38 | end
|
0.003 | 69300 | 39 | elseif isscalar(bcodes) % faster scalar case
|
0.005 | 69300 | 40 | if bcodes > 0 %categorical.undefCode
|
0.051 | 69300 | 41 | t = (acodes == bcodes);
|
| | 42 | else
|
| | 43 | t = false(size(acodes));
|
0.003 | 69300 | 44 | end
|
| | 45 | else
|
| | 46 | t = (acodes == bcodes) & (acodes ~= 0);
|
0.241 | 74690 | 47 | end
|
Other subfunctions in this file are not included in this listing.