CUMPROD Cumulative Product Function

Section: Elementary Functions

Usage

Computes the cumulative product of an n-dimensional array along a given dimension. The general syntax for its use is
  y = cumprod(x,d)

where x is a multidimensional array of numerical type, and d is the dimension along which to perform the cumulative product. The output y is the same size of x. Integer types are promoted to int32. If the dimension d is not specified, then the cumulative sum is applied along the first non-singular dimension.

Function Internals

The output is computed via

Example

The default action is to perform the cumulative product along the first non-singular dimension.
--> A = [5,1,3;3,2,1;0,3,1]
A = 
  <int32>  - size: [3 3]
 
Columns 1 to 3
 5  1  3  
 3  2  1  
 0  3  1  
--> cumprod(A)
ans = 
  <int32>  - size: [3 3]
 
Columns 1 to 3
  5   1   3  
 15   2   3  
  0   6   3  

To compute the cumulative product along the columns:

--> cumprod(A,2)
ans = 
  <int32>  - size: [3 3]
 
Columns 1 to 3
  5   5  15  
  3   6   6  
  0   0   0  

The cumulative product also works along arbitrary dimensions

--> B(:,:,1) = [5,2;8,9];
--> B(:,:,2) = [1,0;3,0]
B = 
  <int32>  - size: [2 2 2]
(:,:,1) = 
 
Columns 1 to 2
 5  2  
 8  9  
(:,:,2) = 
 
Columns 1 to 2
 1  0  
 3  0  
--> cumprod(B,3)
ans = 
  <int32>  - size: [2 2 2]
(:,:,1) = 
 
Columns 1 to 2
  5   2  
  8   9  
(:,:,2) = 
 
Columns 1 to 2
  5   0  
 24   0