Number of Elements on MATLAB

Number of Elements on MATLAB thumbnail
MATLAB handles large amounts of data.

MATLAB is a professional-quality software package for the recording, analysis and display of large amounts of data. MATLAB organizes such data sets in objects called vectors, which are single or multidimensional and also referred to as arrays or matrices. MATLAB makes introspection of the number of elements in vectors straightforward.

  1. Size

    • The MATLAB size() function returns a vector containing the length of each vector dimension, in order.

      my_vector = zeros(100,100,10);
      my_vector_size = size(my_vector);

      This example will return a 3-by-1 vector of value [ 100 100 10 ]. A single-dimensional vector has size of n-by-1, so the size() function will return a 2-by-1 vector of length [ n 1 ].

    Length

    • The length() function in MATLAB returns the length of a single-dimensional vector or the length of the largest dimension. For a 100-by-1 vector, length() will return the scalar value 100. For a 50-by-40-by-30 vector, the length() function will return the scalar value 50.

    Numel

    • The MATLAB function numel() returns a scalar value containing the total number of elements in the vector. For a 100-by-1 vector, numel() will return the scalar value 100. For a 50-by-40-by-30 vector, the numel() function will return the value 60,000 or 50 times 40 times 30. The numel() function is equivalent to calling prod(size(my_vector)), taking the product of the elements in the vector returned by the size() function.

    Ndims

    • The ndims() function in MATLAB returns the number of dimensions in a vector. For a 100-by-1 vector, ndims() returns the scalar value 2; for a 50-by-40-by-30 vector, it returns the scalar value 3. The ndims() function is equivalent to calling length(size(my_vector)), or taking the length of the vector returned by the size() function.

Related Searches:

References

  • Photo Credit John Foxx/Stockbyte/Getty Images

Comments

Related Ads

Featured