| MATLAB Function Reference | ![]() |
Syntax
B = prod(A)
B = prod(A,dim)
Description
B = prod(A)
returns the products along different dimensions of an array.
If A is a vector, prod(A) returns the product of the elements.
If A is a matrix, prod(A) treats the columns of A as vectors, returning a row vector of the products of each column.
If A is a multidimensional array, prod(A) treats the values along the first non-singleton dimension as vectors, returning an array of row vectors.
B = prod(A, takes the products along the dimension of dim)
A specified by scalar dim.
Examples
The magic square of order 3 is
M = magic(3)
M =
8 1 6
3 5 7
4 9 2
The product of the elements in each column is
prod(M) =
96 45 84
The product of the elements in each row can be obtained by:
prod(M,2) =
48
105
72
See Also
| printdlg | profile | ![]() |