How to find the number of elements in an array in Matlab and Octave
To find out the number of elements of a vector, use the length(v) function
length(v)
The function counts the number of elements in an array.
The number of elements in a vector is also called the size of the vector.
Examples
Esempio 1
Define a column vector
>> w=[1;2;3;4;5]
To know the number of elements of the vector use the length() function
>> length(w)
ans = 5
The vector has 5 elements
Example 2
Define a row vector
>> w=[1 2 3 4 5]
To count the number of elements of the vector use the length() function
>> length(w)
ans = 5
The vector has 5 elements
https://how.okpedia.org/en/matlab/how-to-find-the-number-of-elements-in-an-array-in-matlab-and-octave
Report an error or share a suggestion to enhance this page