give size of a matrix in matlab

To determine the size of a matrix in MATLAB, you can use the size function. This function returns a vector [m,n] where m is the number of rows and n is the number of columns.

Here is an example code snippet:

main.m
A = [1 2 3; 4 5 6; 7 8 9];
[m,n] = size(A);
disp(['A has ' num2str(m) ' rows and ' num2str(n) ' columns.']);
109 chars
4 lines

This will output:

main.m
A has 3 rows and 3 columns.
28 chars
2 lines

You can also use the length function to determine the length of the longest edge if you're dealing with a square matrix.

gistlibby LogSnag