length() command or function gives the number of elements in a vector or length of largest matrix size, after reading this MATLAB length topic, you will know the theory and examples.
Syntax:
length(n)
- n can be a vector or matrix.
Example: To find the number of elements in a vector.
% create n vector n=[1,2,3,56]; % to find length of a vector length(n)
Output:
ans = 4
Example: To find the number of elements present in each column the matrix.
% create the 3x4 matrix as n=[1,2,3;3,2,1;4,5,1;23,2,1] % to find length of a matrix length(n)
Output:
n = 1 2 3 3 2 1 4 5 1 23 2 1 ans = 4