To set the size of a matrix in MATLAB, you can use the zeros()
or ones()
function to create a matrix of the desired size. To create a matrix of size m
by n
, you can use:
main.m120 chars3 lines
If you want to change the size of an existing matrix A
, you can use the size()
function. For example, to change the size of A
to m
by n
, you can use:
main.m63 chars2 lines
Alternatively, if you want to change the number of rows or columns of A
without changing the total number of elements, you can use:
main.m64 chars2 lines
You can also use indexing to set the size of a matrix. For example, to create a matrix A
with m
rows and n
columns, you can use:
main.m50 chars5 lines
This creates an empty matrix A
, and then appends m
rows of zeros, each with n
columns.
gistlibby LogSnag