### 4.6 Logical Values ¶

Octave has built-in support for logical values, i.e., variables that are either `true` or `false`. When comparing two variables, the result will be a logical value whose value depends on whether or not the comparison is true.

The basic logical operations are `&`, `|`, and `!`, which correspond to “Logical And”, “Logical Or”, and “Logical Negation”. These operations all follow the usual rules of logic.

It is also possible to use logical values as part of standard numerical calculations. In this case `true` is converted to `1`, and `false` to 0, both represented using double precision floating point numbers. So, the result of `true*22 - false/6` is `22`.

Logical values can also be used to index matrices and cell arrays. When indexing with a logical array the result will be a vector containing the values corresponding to `true` parts of the logical array. See Logical Indexing.

Logical values can also be constructed by casting numeric objects to logical values, or by using the `true` or `false` functions.

`TF =` logical `(x)` ¶

  Convert the numeric object x to logical type.

  Any nonzero values will be converted to true (1) while zero values will be converted to false (0). The non-numeric value NaN cannot be converted and will produce an error.

  Compatibility Note: Octave accepts complex values as input, whereas MATLAB issues an error.

  See also: double, single, char.

`T =` true ¶
`T =` true `(n)` ¶
`T =` true `(m, n, …)` ¶
`T =` true `([m, n, …])` ¶
`T =` true `(…, "like", var)` ¶

  Return a scalar, matrix, or N-dimensional array whose elements are all logical `1`.

  If called with no arguments, return the scalar value logical `1`.

  If invoked with a single scalar integer argument n, return a square NxN matrix.

  If invoked with two or more scalar integer arguments, or a vector of integer values, return an array with the given dimensions.

  If a logical variable var is specified after `"like"`, the output T will have the same sparsity as var.

  Programming Notes: The code `true (…)` is faster (30X) and more memory efficient than `logical (ones (…))`.

  Any negative dimensions are treated as zero, and any zero dimensions will result in an empty matrix. This odd behavior is for MATLAB compatibility.

  See also: false, logical, ones, zeros.

`F =` false ¶
`F =` false `(n)` ¶
`F =` false `(m, n, …)` ¶
`F =` false `([m, n, …])` ¶
`F =` false `(…, "like", var)` ¶

  Return a scalar, matrix, or N-dimensional array whose elements are all logical `0`.

  If called with no arguments, return the scalar value logical `0`.

  If invoked with a single scalar integer argument n, return a square NxN matrix.

  If invoked with two or more scalar integer arguments, or a vector of integer values, return an array with the given dimensions.

  If a logical variable var is specified after `"like"`, the output F will have the same sparsity as var.

  Programming Note: The code `false (…)` is faster (30X) and more memory efficient than `logical (zeros (…))`.

  Any negative dimensions are treated as zero, and any zero dimensions will result in an empty matrix. This odd behavior is for MATLAB compatibility.

  See also: true, logical, ones, zeros.