|
XploRe has no specific data type for boolean values. The boolean value true is encoded by 1, whereas the value false is encoded by 0. Hence, all matrix operations for numeric matrices can be used for boolean expressions as well. Note that many functions which require boolean input only check if the input is false or not.
Let us consider which can be found in
XLGmatrix03.xpl
.
A = (2|4)~(8|8) B = (5|6)~(4|8) A > BThe last instruction, i.e. the comparison yields
Contents of _tmp [1,] 0 1 [2,] 0 0which means that only the element in the first row and second column of A is greater than the corresponding element of B. Similarly,
A == Bgives
Contents of _tmp [1,] 0 0 [2,] 0 1Note that A == B is different from the assignment A = B, which would create A as a copy of the matrix B.
You may check now that the instruction
(A > B) || (A == B)which checks if ''A > B or A == B'' is identical to
A >= BBoth instructions return
Contents of _tmp [1,] 0 1 [2,] 0 1which means that both values in the second column fulfill the >= condition.
Let us point out again that all introduced comparison
operators work elementwise. They extend to arrays as usual.
To verify a condition for all
elements of a matrix or an array, the
prod
function can be used:
prod(prod(A==B),2)would return 1 in the case that all elements of the matrices A and B are identical. We will learn more about