numel
Number of elements in an array.
Category: Language Fundamentals > Matrices and Arrays
Syntax
n = numel(A)
Returns prod(size(A)).
Description
numel counts elements whatever the shape, so a 3-by-4 matrix has 12. A character vector counts characters, a cell array counts cells (not what is inside them), and a struct array counts structs. A string array counts strings, so numel("hello") is 1, while strlength gives the characters.
Input arguments
A- Array of any type: numeric, text, cell, struct array, table.
Output arguments
n- Nonnegative integer scalar.
Example
numel(ones(2, 3))
numel('hello')
numel({1, 'ab', [1 2 3]})
numel("hello")
Output
ans = 6
ans = 5
ans = 3
ans = 1