true

Logical true value, or an array filled with logical true.

Category: Language Fundamentals > Matrices and Arrays

Syntax

t = true

Returns the scalar logical 1.

T = true(n)

Returns an n-by-n logical matrix of ones.

T = true(m, n, ...)

Returns a logical array of the given size.

T = true(sz)

Takes the size from the vector sz.

Description

true creates values of class logical, which take one byte each and behave as 0 and 1 in arithmetic. It is the usual way to build a mask that selects everything, to be switched off selectively later.

true is a function call, not a literal, so true(3) is a matrix and not the number three.

Input arguments

n, m, ...
Nonnegative integers giving the dimensions. Negative values count as 0.
sz
Size vector.

Output arguments

T
Logical array whose elements are all 1.

Example

t = true
M = true(2, 3);
M(1, 2) = false
class(M)
Output
t = logical
   1
M = 2×3 logical array

   1   0   1
   1   1   1
ans = 'logical'

See also

false logical ones zeros