MATLAB length

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];

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]

length(n)

Output:

n =

1   2   3
3   2   1
4   5   1
23  2   1


ans =

4

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *