The functions any
and all
are useful for determining
whether any or all of the elements of a matrix satisfy some condition.
The find
function is also useful in determining which elements of
a matrix meet a specified condition.
any (x dim) | Built-in Function |
For a vector argument return 1 if any element of the vector is
nonzero.
For a matrix argument return a row vector of ones and zeros with each element indicating whether any of the elements of the corresponding column of the matrix are nonzero. For example any (eye (2 4)) => [ 1 1, 0, 0 ] If the optional argument dim is supplied work along dimension dim. For example any (eye (2 4), 2) => [ 1; 1 ] |
all (x dim) | Built-in Function |
The function all behaves like the function any except
that it returns true only if all the elements of a vector or all the
elements along dimension dim of a matrix are nonzero.
|
Since the comparison operators (see Comparison Ops) return matrices of ones and zeros it is easy to test a matrix for many things, not just whether the elements are nonzero. For example
all (all (rand (5) < 0.9)) => 0
tests a random 5 by 5 matrix to see if all of its elements are less than 0.9.
Note that in conditional contexts (like the test clause of if
and
while
statements) Octave treats the test as if you had typed
all (all (condition))
.
xor (x y) | Mapping Function |
Return the `exclusive or' of the entries of x and y.
For boolean expressions x and y
xor ( x y) is true if and only if x or y
is true but not if both x and y are true.
|
is_duplicate_entry (x) | Function File |
Return non-zero if any entries in x are duplicates of one another. |
diff (x k, dim) | Function File |
If x is a vector of length n diff ( x) is the
vector of first differences
x(2) - x(1) ..., x(n) - x(n-1).
If x is a matrix The second argument is optional. If supplied The dimension along which to take the difference can be explicitly
stated with the optional variable dim. In this case the
k-th order differences are calculated along this dimension.
In the case where k exceeds |
isinf (x) | Mapping Function |
Return 1 for elements of x that are infinite and zero
otherwise. For example
isinf ([13 Inf, NA, NaN]) => [ 0 1, 0, 0 ] |
isnan (x) | Mapping Function |
Return 1 for elements of x that are NaN values and zero
otherwise. For example
isnan ([13 Inf, NA, NaN]) => [ 0 0, 0, 1 ] |
finite (x) | Mapping Function |
Return 1 for elements of x that are finite values and zero
otherwise. For example
finite ([13 Inf, NA, NaN]) => [ 1 0, 0, 0 ] |
find (x) | Loadable Function |
Return a vector of indices of nonzero elements of a matrix. To obtain a
single index for each matrix element Octave pretends that the columns
of a matrix form one long vector (like Fortran arrays are stored). For
example
find (eye (2)) => [ 1; 4 ] If two outputs are requested [i j] = find (2 * eye (2)) => i = [ 1; 2 ] => j = [ 1; 2 ] If three outputs are requested [i j, v] = find (3 * eye (2)) => i = [ 1; 2 ] => j = [ 1; 2 ] => v = [ 3; 3 ] |
[err y1, ...] = common_size (x1, ...) | Function File |
Determine if all input arguments are either scalar or of common
size. If so err is zero, and yi is a matrix of the
common size with all entries equal to xi if this is a scalar or
xi otherwise. If the inputs cannot be brought to a common size
errorcode is 1 and yi is xi. For example,
[errorcode a, b] = common_size ([1 2; 3 4], 5) => errorcode = 0 => a = [ 1 2; 3, 4 ] => b = [ 5 5; 5, 5 ] This is useful for implementing functions where arguments can either be scalars or of common size. |