OKPEDIA MATLAB EN VETTORI

How to count the number of elements in a vector in Matlab and Octave

To count the number of elements of a vector in Matlab and Octave use the length function

length(v)

The v parameter is the name of the array variable (vector).

The function returns the number of elements in the vector.

Note. The length function calculates the length of a row vector or column vector.

Example

Define a vector

>> v=['a';'b';'c';'d';'e']

To find out the number of elements in the vector use the length() function

>> length(v)
ans = 5

The vector has 5 elements.

https://how.okpedia.org/en/matlab/how-to-count-the-number-of-elements-in-a-vector-in-matlab-and-octave


Report an error or share a suggestion to enhance this page


Arrays and Vectors


FacebookTwitterLinkedinLinkedin