Integer or an array of unsigned integers.
C = BITCMP(A,N) returns the bit-wise complement of A as an N-bit
unsigned integer. A may not have any bits sets higher than N, i.e. may
not have value greater than 2^N-1. The largest value of N is the number of
bits in the unsigned integer class of A, e.g., the largest value for
UINT32s is N=32.
Example:
a = uint16(intmax('uint8'))
bitcmp(a,8)
See also bitand, bitor, bitxor, bitshift, bitset, bitget, intmax.
Reference page in Help browser
doc bitcmp
<bitor> - Bit-wise OR.
BITOR Bit-wise OR.
C = BITOR(A,B) returns the bitwise OR of arguments A and B,
where A and B are unsigned integers or arrays of unsigned integers.
Example:
Create a truth table:
A = uint8([0 1; 0 1])
B = uint8([0 0; 1 1])
TT = bitor(A,B)
See also bitand, bitxor, bitshift, bitcmp, bitset, bitget, intmax.
Overloaded methods:
codistributed/bitor
Reference page in Help browser
doc bitor
<bitmax> - Maximum floating point integer.
BITMAX Maximum double precision floating point integer.
BITMAX returns the maximum unsigned double precision floating point
integer. It is the value when all bits in the mantissa are set, 2^53-1.
Instead of integer valued double precision variables, use unsigned
integers for bit manipulations and replace BITMAX with INTMAX.
Example:
Display in different formats the largest floating point integer
and the largest 32 bit unsigned integer.
>> format long e
>> bitmax
ans =
9.007199254740991e+015
>> intmax('uint32')
ans =
4294967295
>> format hex
>> bitmax
ans =
433fffffffffffff
>> intmax('uint32')
ans =
ffffffff
Note: the last 13 hex digits of BITMAX are "f", corresponding to 52
1's (all 1's) in the mantissa of the binary representation. The
first 3 hex digits correspond to the sign bit 0 and the 11 bit
biased exponent 10000110011 in binary (1075 in decimal), and the
actual exponent is (1075-1023)=52. Thus the binary value of BITMAX
is 1.111...111x2^52 with 52 trailing 1's, or 2^53-1.
See also intmax, bitand, bitor, bitxor, bitcmp, bitshift, bitset, bitget.
Reference page in Help browser
doc bitmax
<bitxor> - Bit-wise XOR.
BITXOR Bit-wise XOR.
C = BITXOR(A,B) returns the bitwise XOR of arguments A and B,
where A and B are unsigned integers or arrays of unsigned integers.
Example:
Create a truth table:
A = uint8([0 1; 0 1])
B = uint8([0 0; 1 1])
TT = bitxor(A,B)
See also bitor, bitand, bitcmp, bitshift, bitset, bitget, intmax.
Overloaded methods:
codistributed/bitxor
Reference page in Help browser
doc bitxor
<bitset> - Set bit.
BITSET Set bit.
C = BITSET(A,BIT) sets bit position BIT in A to 1 (on). A must be an
unsigned integer or an array of unsigned integers, and BIT must be a
number between 1 and the length in bits of the unsigned integer class
of A, e.g., 32 for UINT32s.
C = BITSET(A,BIT,V) sets the bit at position BIT to the value V.
V must be either 0 or 1.
Example:
Repeatedly subtract powers of 2 from the largest UINT32 value:
a = intmax('uint32')
for i = 1:32, a = bitset(a,32-i+1,0), end
See also bitget, bitand, bitor, bitxor, bitcmp, bitshift, intmax.
Reference page in Help browser
doc bitset
<bitget> - Get bit.
BITGET Get bit.
C = BITGET(A,BIT) returns the value of the bit at position BIT in A. A
must be an unsigned integer or an array of unsigned integers, and BIT
must be a number between 1 and the number of bits in the unsigned
integer class of A e.g., 32 for UINT32s.
Example:
Prove that INTMAX sets all the bits to 1:
a = intmax('uint8')
if all(bitget(a,1:8)), disp('All the bits have value 1.'), end
See also bitset, bitand, bitor, bitxor, bitcmp, bitshift, intmax.
Reference page in Help browser
doc bitget
<bitshift> - Bit-wise shift.
BITSHIFT Bit-wise shift.
C = BITSHIFT(A,K) returns the value of A shifted by K bits. A must be
an unsigned integer or an array of unsigned integers. Shifting by K
is the same as multiplication by 2^K. Negative values of K are allowed
and this corresponds to shifting to the right, or dividing by 2^ABS(K)
and truncating to an integer. If the shift causes C to overflow
the number of bits in the unsigned integer class of A, then the
overflowing bits are dropped.
C = BITSHIFT(A,K,N) will cause bits overflowing N bits to be dropped.
N must be less than or equal to the length in
bits of the unsigned integer class of A, e.g., N<=32 for UINT32.
Instead of using BITSHIFT(A,K,8) or another power of 2 for N, consider
using BITSHIFT(UINT8(A),K) or the appropriate unsigned integer class
for A.
Example:
Repeatedly shift the bits of an unsigned 16 bit value to the left
until all the nonzero bits overflow. Track the progress in binary.
a = intmax('uint16');
disp(sprintf('Initial uint16 value %5d is %16s in binary', ...
a,dec2bin(a)))
for i = 1:16
a = bitshift(a,1);
disp(sprintf('Shifted uint16 value %5d is %16s in binary',...
a,dec2bin(a)))
end
See also bitand, bitor, bitxor, bitcmp, bitset, bitget, bitmax, intmax.
Reference page in Help browser
doc bitshift
Set operators.
<union> - Set union.
UNION Set union.
UNION(A,B) for vectors A and B, returns the combined values of the two
vectors with no repetitions. MATLAB sorts the results. A and B can be
cell arrays of strings.
UNION(A,B,'rows') for matrices A are B that have the same number of
columns, returns the combined rows from the two matrices with no
repetitions. MATLAB ignores the 'rows' flag for all cell arrays.
[C,IA,IB] = UNION(...) also returns index vectors IA and IB such
that C is a sorted combination of the elements A(IA) and B(IB)
(or A(IA,:) and B(IB,:)).
Class support for inputs A,B:
float: double, single
See also unique, intersect, setdiff, setxor, ismember.
Overloaded methods:
cell/union
xregpointer/union
ordinal/union
nominal/union
categorical/union
Reference page in Help browser
doc union
<unique> - Set unique.
UNIQUE Set unique.
B = UNIQUE(A) for the array A returns the same values as in A but
with no repetitions. B will also be sorted. A can be a cell array of
strings.
UNIQUE(A,'rows') for the matrix A returns the unique rows of A.
[B,I,J] = UNIQUE(...) also returns index vectors I and J such
that B = A(I) and A = B(J) (or B = A(I,:) and A = B(J,:)).
[B,I,J] = UNIQUE(...,'first') returns the vector I to index the
first occurrence of each unique value in A. UNIQUE(...,'last'),
the default, returns the vector I to index the last occurrence.
See also union, intersect, setdiff, setxor, ismember, sort, issorted.
Overloaded methods:
cell/unique
RTW.unique
xregpointer/unique
guidarray/unique
dataset/unique
categorical/unique
Reference page in Help browser
doc unique
<intersect> - Set intersection.
INTERSECT Set intersection.
INTERSECT(A,B) for vectors A and B, returns the values common to the
two vectors. MATLAB sorts the results. A and B can be cell arrays of
strings.
INTERSECT(A,B,'rows') for matrices A and B that have the same number of
columns, returns the rows common to the two matrices. MATLAB ignores
the 'rows' flag for all cell arrays.
[C,IA,IB] = INTERSECT(A,B) also returns index vectors IA and IB
such that C = A(IA) and C = B(IB).
[C,IA,IB] = INTERSECT(A,B,'rows') also returns index vectors IA and IB
such that C = A(IA,:) and C = B(IB,:).
Class support for inputs A,B:
float: double, single
See also unique, union, setdiff, setxor, ismember.
Overloaded methods:
cell/intersect
xregpointer/intersect
ordinal/intersect
nominal/intersect
categorical/intersect
Reference page in Help browser
doc intersect
<setdiff> - Set difference.
SETDIFF Set difference.
SETDIFF(A,B) when A and B are vectors returns the values
in A that are not in B. The result will be sorted. A and B
can be cell arrays of strings.
SETDIFF(A,B,'rows') when A are B are matrices with the same
number of columns returns the rows from A that are not in B.
[C,I] = SETDIFF(...) also returns an index vector I such that
C = A(I) (or C = A(I,:)).
See also unique, union, intersect, setxor, ismember.
Overloaded methods:
cell/setdiff
xregpointer/setdiff
guidarray/setdiff
ordinal/setdiff
nominal/setdiff
categorical/setdiff
Reference page in Help browser
doc setdiff
<setxor> - Set exclusive-or.
SETXOR Set exclusive-or.
SETXOR(A,B) when A and B are vectors returns the values that are
not in the intersection of A and B. The result will be sorted.
A and B can be cell arrays of strings.
SETXOR(A,B,'rows') when A are B are matrices with the same number
of columns returns the rows that are not in the intersection
of A and B.
[C,IA,IB] = SETXOR(...) also returns index vectors IA and IB such
that C is a sorted combination of the elements of A(IA) and B(IB)
(or A(IA,:) and B(IB,:)).
See also unique, union, intersect, setdiff, ismember.
Overloaded methods:
cell/setxor
ordinal/setxor
nominal/setxor
categorical/setxor
Reference page in Help browser
doc setxor
<ismember> - True for set member.
ISMEMBER True for set member.
ISMEMBER(A,S) for the array A returns an array of the same size as A
containing 1 where the elements of A are in the set S and 0 otherwise.
A and S can be cell arrays of strings.
ISMEMBER(A,S,'rows') when A and S are matrices with the same
number of columns returns a vector containing 1 where the rows of
A are also rows of S and 0 otherwise.
[TF,LOC] = ISMEMBER(...) also returns an array LOC containing the
highest absolute index in S for each element in A which is a member of S
and 0 if there is no such index.
Class support for inputs A,S:
float: double, single
See also unique, intersect, setdiff, setxor, union.
Overloaded methods:
cell/ismember
xregpointer/ismember
guidarray/ismember
cgprojconnections/ismember
ordinal/ismember
nominal/ismember
categorical/ismember
Reference page in Help browser
doc ismember