Logical Functions

all

Check whether all the elements are true.

Syntax

v = all(M)
v = all(M,dim)
b = all(v)

Description

all performs a logical AND on the elements of the columns of a matrix, or the elements of a vector. If a second argument dim is provided, the operation is performed column by column if dim is 1, and row by row if it is 2.

all can be omitted if its result would be used in the statement if or while, because these statements consider a matrix to be true if all the elements of the matrix are nonzero.

Examples

all([1,2,3] == 2)
  false
all([1,2,3] > 0)
  true

See also

any, operator &

any

Check whether any element is true.

Syntax

v = any(M)
v = any(M,dim)
b = any(v)

Description

any performs a logical OR on the elements of the columns of a matrix, or the elements of a vector. If a second argument dim is provided, the operation is performed column by column if dim is 1, and row by row if it is 2.

Examples

any([1,2,3] == 2)
  true
any([1,2,3] > 5)
  false

See also

all, operator |

bitand

Bitwise AND.

Syntax

c = bitand(a, b)

Description

The input arguments are converted to 32-bit unsigned integers; each bit of the result is the binary AND of the corresponding bits of the inputs.

The inputs can be scalar, matrices of the same size, or a scalar and a matrix.

Examples

bitand(1,3)
  1
bitand(1:6,1)
  1 0 1 0 1 0

See also

bitor, bitxor, bitget

bitcmp

Bit complement (bitwise NOT).

Syntax

b = bitcmp(a, n)

Description

The first input argument is converted to a unsigned integer of n bits, and these bits are inverted.

The inputs can be scalar, matrices of the same size, or a mix of both.

Examples

bitcmp(1,4)
  14
bitcmp(0, 1:8)
  1 3 7 15 31 63 127 255

See also

bitxor, operator ~

bitget

Bit extraction.

Syntax

b = bitget(a, n)

Description

The first input argument is converted to 32-bit unsigned integers; the result is the n:th bit, where 1 is the least significant bit and 32 is the most significant one.

The inputs can be scalar, matrices of the same size, or a scalar and a matrix.

Examples

bitget(123,5)
  1
bitget(7, 1:8)
  1 1 1 0 0 0 0 0

See also

bitand, bitor, bitxor, bitshift

bitor

Bitwise OR.

Syntax

c = bitor(a, b)

Description

The input arguments are converted to 32-bit unsigned integers; each bit of the result is the binary OR of the corresponding bits of the inputs.

The inputs can be scalar, matrices of the same size, or a scalar and a matrix.

Examples

bitor(1,2)
  3
bitor(1:6,1)
  1 3 3 5 5 7

See also

bitand, bitxor, bitget

bitshift

Bit shift.

Syntax

b = bitshift(a, shift)
b = bitshift(a, shift, n)

Description

The first input argument is converted to a 32-bit unsigned integer, and shifted by shift bits, to the left if shift is positive or to the right if it is negative. With a third argument n, only n bits are retained.

The inputs can be scalar, matrices of the same size, or a mix of both.

Examples

bitshift(1,3)
  8
bitshift(8, -2:2)
  2 4 8 16 32
bitshift(15, 0:3, 4)
  15 14 12 8

See also

bitget

bitxor

Bitwise exclusive OR.

Syntax

c = bitxor(a, b)

Description

The input arguments are converted to 32-bit unsigned integers; each bit of the result is the binary exclusive OR of the corresponding bits of the inputs.

The inputs can be scalar, matrices of the same size, or a scalar and a matrix.

Examples

bitxor(1,3)
  2
bitxor(1:6,1)
  0 3 2 5 4 7

See also

bitcmp, bitand, bitor, bitget

false

Boolean constant false.

Syntax

b = false

Description

The boolean constant false can be used to set the value of a variable. It is equivalent to logical(0). The constant 0 is equivalent in many cases; indices (to get or set the elements of a matrix) are an important exception.

Examples

false
  false
islogical(false)
  true

See also

true, logical

islogical

Test for a boolean object.

Syntax

b = islogical(obj)

Description

islogical(obj) is true if obj is a logical value, and false otherwise. The result is always a scalar, even if obj is a matrix. Logical values are obtained with comparison operators, logical operators, test functions, and the function logical.

Examples

islogical(eye(10))
  false
islogical(~eye(10))
  true

See also

logical, isnumeric, isstr

logical

Transform a number into a boolean.

Syntax

b = logical(x)

Description

logical(x) sets the logical flag associated to x. The logical flag has an effect only when x is used to access the elements of a variable, and in the argument of islogical or ===.

Examples

a=1:3; a([1,0,1])
Index out of range
a=1:3; a(logical([1,0,1]))
  1 3

See also

islogical, double, char, setstr, operator ()

true

Boolean constant true.

Syntax

b = true

Description

The boolean constant true can be used to set the value of a variable. It is equivalent to logical(1). The constant 1 is equivalent in many cases; indices (to get or set the elements of a matrix) are an important exception.

Examples

true
  true
islogical(true)
  true

See also

false, logical

xor

Exclusive or.

Syntax

b3 = xor(b1,b2)

Description

xor(b1,b2) performs the exclusive or operation between the corresponding elements of b1 and b2. b1 and b2 must have the same size or one of them must be a scalar.

Examples

xor([false false true true],[false true false true])
  F T T F
xor(pi,8)
  false

See also

operator &, operator |


Copyright 1998-2001, Calerga.

All rights reserved.