To get the amount of rows in an array in MATLAB, you can use either the size
or length
function. Here's an example using the size
function:
main.m50 chars3 lines
In this example, A
is a 3x3 array. The second argument of the size
function specifies the dimension you want to query (in this case, the rows). The output of size(A, 1)
is 3, which is the number of rows in A
.
You can also use the length
function, although it behaves in a slightly different way. The length
function gives the length of the largest dimension of an array. So if you have a 3x3 array, length
will return 3, which is the length of the rows or columns:
main.m49 chars3 lines
In this case, num_rows
is also 3, which is the length of the rows in A
.
gistlibby LogSnag