| GNU Octave Manual Version 3 by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |
16.4 Special Utility Matrices
- Built-in Function: eye (x)
- Built-in Function: eye (n, m)
- Built-in Function: eye (..., class)
- Return an identity matrix. If invoked with a single scalar argument,
eyereturns a square matrix with the dimension specified. If you supply two scalar arguments,eyetakes them to be the number of rows and columns. If given a vector with two elements,eyeuses the values of the elements as the number of rows and columns, respectively. For example,eye (3) => 1 0 0 0 1 0 0 0 1The following expressions all produce the same result:
eye (2) == eye (2, 2) == eye (size ([1, 2; 3, 4])
The optional argument class, allows
eyeto return an array of the specified type, likeval = zeros (n,m, "uint8")
Calling
eyewith no arguments is equivalent to calling it with an argument of 1. This odd definition is for compatibility with Matlab.
- Built-in Function: ones (x)
- Built-in Function: ones (n, m)
- Built-in Function: ones (n, m, k, ...)
- Built-in Function: ones (..., class)
- Return a matrix or N-dimensional array whose elements are all 1.
The arguments are handled the same as the arguments for
eye.If you need to create a matrix whose values are all the same, you should use an expression like
val_matrix = val * ones (n, m)
The optional argument class, allows
onesto return an array of the specified type, for exampleval = ones (n,m, "uint8")
- Built-in Function: zeros (x)
- Built-in Function: zeros (n, m)
- Built-in Function: zeros (n, m, k, ...)
- Built-in Function: zeros (..., class)
- Return a matrix or N-dimensional array whose elements are all 0.
The arguments are handled the same as the arguments for
eye.The optional argument class, allows
zerosto return an array of the specified type, for exampleval = zeros (n,m, "uint8")
- Function File: repmat (A, m, n)
- Function File: repmat (A, [m n])
- Function File: repmat (A, [m n p ...])
- Form a block matrix of size m by n, with a copy of matrix A as each element. If n is not specified, form an m by m block matrix.
- Built-in Function: diag (v, k)
- Return a diagonal matrix with vector v on diagonal k. The
second argument is optional. If it is positive, the vector is placed on
the k-th super-diagonal. If it is negative, it is placed on the
-k-th sub-diagonal. The default value of k is 0, and the
vector is placed on the main diagonal. For example,
diag ([1, 2, 3], 1) => 0 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0Given a matrix argument, instead of a vector,
diagextracts the k-th diagonal of the matrix.
The functions linspace and logspace make it very easy to
create vectors with evenly or logarithmically spaced elements.
See section 4.2 Ranges.
- Built-in Function: linspace (base, limit, n)
- Return a row vector with n linearly spaced elements between
base and limit. If the number of elements is greater than one,
then the base and limit are always included in
the range. If base is greater than limit, the elements are
stored in decreasing order. If the number of points is not specified, a
value of 100 is used.
The
linspacefunction always returns a row vector.For compatibility with Matlab, return the second argument if fewer than two values are requested.
- Function File: logspace (base, limit, n)
- Similar to
linspaceexcept that the values are logarithmically spaced from 10^base to 10^limit.If limit is equal to pi,
the points are between 10^base and pi,
not 10^base and 10^pi,
in order to be compatible with the corresponding Matlab function.
Also for compatibility, return the second argument if fewer than two values are requested.
See also linspace
| ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |