MATLAB Function Reference Previous page   Next Page
numel

Number of elements in array or subscripted array expression

Syntax

Description

n = numel(A) returns the number of elements, n, in array A.

n = numel(A,varargin) returns the number of subscripted elements, n, in A(index1,index2,...,indexn), where varargin is a cell array whose elements are index1, index2, ..., indexn.

MATLAB implicitly calls the numel built-in function whenever an expression such as A{index1,index2,...,indexN} or A.fieldname generates a comma-separated list.

numel works with the overloaded subsref and subsasgn functions. It computes the number of expected outputs (nargout) returned from subsref. It also computes the number of expected inputs (nargin) to be assigned using subsasgn. The nargin value for the overloaded subsasgn function consists of the variable being assigned to, the structure array of subscripts, and the value returned by numel.

As a class designer, you must ensure that the value of n returned by the built-in numel function is consistent with the class design for that object. If n is different from either the nargout for the overloaded subsref function or the nargin for the overloaded subsasgn function, then you need to overload numel to return a value of n that is consistent with the class' subsref and subsasgn functions. Otherwise, MATLAB produces errors when calling these functions.

Examples

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

See Also

nargin, nargout, prod, size, subsasgn, subsref


Previous page  num2str nzmax Next page

© 1994-2005 The MathWorks, Inc.