Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

numel

Number of array elements

Syntax

Description

example

n = numel(A) returns the number of elements, n, in array A, equivalent to prod(size(A)).

Examples

collapse all

Create a 4-by-4-by-2 matrix.

A = magic(4);
A(:,:,2) = A'
A(:,:,1) =

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1


A(:,:,2) =

    16     5     9     4
     2    11     7    14
     3    10     6    15
    13     8    12     1

numel counts 32 elements in the matrix.

n = numel(A)
n =

    32

Create a cell array of character vectors.

A = {'dog','cat','fish','horse'};

numel counts 4 elements in the array.

n = numel(A)
n =

     4

Create a table with four variables listing patient information for five people.

LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80];

A = table(Age,Height,Weight,BloodPressure,'RowNames',LastName)
A = 

                Age    Height    Weight    BloodPressure
                ___    ______    ______    _____________

    Smith       38     71        176       124     93   
    Johnson     43     69        163       109     77   
    Williams    38     64        131       125     83   
    Jones       40     67        133       117     75   
    Brown       49     64        119       122     80   

Find the number of elements in the table.

n = numel(A)
n =

    20

numel returns a value equivalent to prod(size(A)) corresponding to the 5 rows and 4 variables.

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | cell | table | timetable | categorical | datetime | duration | calendarDuration

Limitations

  • If A is a table, numel returns the number of elements in the table, A, equivalent to prod(size(A)). Variables in a table can have multiple columns, but numel(A) only accounts for the number of rows and number of variables.

More About

collapse all

Tall Array Support

This function supports tall arrays with the limitation:

The syntax N = numel(T, INDEX1, INDEX2, ...) is not supported for tall arrays.

For more information, see Tall Arrays.

See Also

| |

Introduced before R2006a


Was this topic helpful?