true
or false
), dates and times, strings, or some other MATLAB data type. double
. zeros
and ones
functions create matrices of all zeros or all ones. The first and second arguments of these functions are the number of rows and number of columns of the matrix, respectively.diag
function places the input elements on the diagonal of a matrix. For example, create a row vector A
containing four elements. Then, create a 4-by-4 matrix whose diagonal elements are the elements of A
.A
and B
as two rows of a matrix, use the semicolon.horzcat
, which horizontally concatenates two compatible input matrices.colon
is a handy way to create matrices whose elements are sequential and evenly spaced. For example, create a row vector whose elements are the integers from 1 to 10.for
loop, it's usually best to preallocate space for the largest matrix you anticipate creating. Without preallocation, MATLAB has to allocate memory every time the size increases, slowing down operations. For example, preallocate a matrix that holds up to 10,000 rows and 10,000 columns by initializing its elements to zero.A
.find
function returns an empty vector of indices, indicating that it couldn't find any elements less than 0. isempty
function.