How to Calculate Cumulative Product in MATLAB Last Updated : 04 Jul, 2022 Comments Improve Suggest changes Like Article Like Report The cumulative product of a sequence is a running products or partial products of a sequence The cumulative products of the sequence {a,b,c,...}, are a, a*b, a*b*c, .... Matlab allows us to calculate the cumulative product of a vector, matrix using cumprod() method. Different syntaxes of cumprod() method are B = cumprod(A)B = cumprod(A,dim)B = cumsprod(___,direction)B = cumprod(___,nanflag) Now we will discuss the above syntaxes in detail: B = cumprod(A)The method returns the cumulative product of A starting at the beginning of array A.If A is a vector, then it returns the cumulative product of sequence AIf A is a matrix, then it returns the cumulative product along each column of A. Example 1: Matlab % Input vector A = 2:8; B = cumprod(A); % Displays cumulative % products of A disp(B) Output : Example 2: Matlab % Input matrix A = [1 4 7; 2 5 8; 3 6 9]; disp("Matrix :") disp(A) B = cumprod(A); % Display cumulative product of matrix A disp("Cumulative product :") disp(B) Output : B = cumprod(A,dim)Returns the cumulative product of matrix A along with each dim.dim takes two values 1 or 2.dim = 1, refers to along each column.dim = 2, refers along each row. Matlab % input matrix A = [1 3 5; 2 4 6]; disp("Matrix :") disp(A) % Cumulative product along each % row from left to right B = cumprod(A,2); disp("Cumulative product :") disp(B); Output :Â B = cumprod(___,direction)Returns the cumulative product of the input vector or matrix in the given direction.direction takes two values 'forward' or 'reverse'If the direction is 'reverse', then calculates cumulative product in reverse i.e if we are considering matrix along each column, then it returns cumulative product starting from bottom to top of each column. Matlab % input matrix A = [1 3 5; 2 4 6]; disp("Matrix :") disp(A) % Cumulative product of A along each row % starting from right to left B = cumprod(A,2,'reverse'); disp("Cumulative product :") disp(B) Output : B = cumprod(___,nanflag)nanflag value decides whether to include or exclude NaN value of the vector in cumulative product or not.nanflag takes two values 'includenan' or 'omitnan' corresponds to including NaN elements and excluding NaN elements respectively.'omitNaN' considers NaN values as 1. Note: NaN * number = NaN Matlab % Input vector A = [3 5 NaN 9 0 NaN]; disp("Vector :"); disp(A); % Including NaN values B = cumprod(A,'includenan'); disp("Cumulative product Include NaN :"); disp(B); % Excluding NaN values B = cumprod(A,'omitnan'); disp("Cumulative product Exclude NaN :"); disp(B); Â Output : Comment More infoAdvertise with us Next Article How to Calculate Cumulative Product in MATLAB M ManikantaBandla Follow Improve Article Tags : Software Engineering MATLAB-Maths Similar Reads How to Calculate Covariance in MATLAB Covariance is the measure of the strength of correlation between two or more random variables. Covariance of two random variables X and Y can be defined as:{\displaystyle \operatorname {cov} (X,Y)={\frac {1}{n}}\sum _{i=1}^{n}(x_{i}-E(X))(y_{i}-E(Y))}Where E(X) and E(Y) are expectation or mean of ra 3 min read How To Calculate Cumulative Sum By Group In R The sum of a collection of numbers as the sum value increases with the number sequence is known as the cumulative sum. In data analysis tasks, it is essential to calculate cumulative sums within groups. This operation helps when we deal with time series or categorical data. In this article, we will 5 min read How to Calculate Cumulative Frequency table in Excel? Cumulative Frequency is the running total of frequencies starting from the very first frequency up to the last frequency. If we simplify the term running total, we can say the first frequency is added with the second frequency and then their sum is added to the third frequency and the same sequence 2 min read How to Easily Calculate the Dot Product in Excel? The dot product is the sum of the product of two vectors. For example, two vectors are v1 = [2, 3, 1, 7] and v2 = [3, 6, 1, 5]. The sum of the product of two vectors is 2 Ã 3 + 3 Ã 6 + 1 Ã 1 = 60. We can use the = SUMPRODUCT(Array1, Array2) function to calculate dot product in excel. Dot Product The 2 min read Create a cumulative histogram in Matplotlib The histogram is a graphical representation of data. We can represent any kind of numeric data in histogram format. In this article, We are going to see how to create a cumulative histogram in Matplotlib Cumulative frequency: Cumulative frequency analysis is the analysis of the frequency of occurren 2 min read Like