MATLAB Function Reference    
numel

Number of elements in a matrix

Syntax

Description

n = numel(a) returns the scalar count, n, of the number of elements in the matrix, a.

numel(a) gives the same answer as prod(size(a)). However, if the size function has been overloaded, prod(size(a)) may not provide an accurate count.

numel can also be used with subsref to determine the number of values that will be returned from a particular call to subsref. See the second example below to see how to use this.

Examples

Create a 4-by-4-by-2 matrix. numel counts 32 elments in the matrix.

In this example, numel indicates that stockobj(3) references six values. The indexed reference to stockobj is made using subsref.

Calling subsref on stockobj(3) does indeed return six values.

See Also

size, prod, subsref


 num2str nzmax