prodProduct of elements in an array
p = prod(A)A is a scalar, P is equal to A.A is a vector, p is the product of all elements along the longer dimension of A.P is the product of all elements of the corresponding vector of A along the first non-singleton dimension.A is empty, it returns an empty array. p = prod(A, k)P corresponds to a vector of A along its k-th dimension.k-th dimension has zero length, then it returns an empty array. 💡 When multiplying numbers by
prod, if any one of them isNaN, the result will beNaN.
a is given by the product of all elements in its size vector.% A random array.
a = rand(3,4,5,6,7,1,2);
% Product of all elements in the size vector.
n = prod(size(a))
% Using the built-in function numel.
numel(a)
n =
5040.0
ans =
5040.0