I would appreciate any help in trying to calculate the Cumulative Distribution Array of a Probability Mass Array when dimensions > 2, essentially a discrete joint cumulative distribution from a sample of data. MATLAB syntax would be most preferred. In a bivariate case (2 dimensions), the following works well:

`cumsum(cumsum(epdf,1),2)./total`

, where `cumsum`

calculates the cumulative sum across the first and second dimensions.

Unfortunately, `cumsum`

doesn't support more than 2 dimensions, at least from what I can tell. The following is a simple 3D PDF I'm testing on in MATLAB. Thank you for any suggestions.

`ePDF(1,1,1) = 1; ePDF(2,1,1) = 2; ePDF(1,2,1) = 3; ePDF(2,2,1) = 4; ePDF(1,1,2) = 5; ePDF(2,1,2) = 6; ePDF(1,2,2) = 7; ePDF(2,2,2) = 8; total = 36; `

Edit: I found an N-Dimensional CumSum function from the open source program FreeMat which does exactly what I need. Is there a way to replicate this function easily in Matlab?

http://freemat.sourceforge.net/help/elementary_cumsum.html

**Contents**hide

#### Best Answer

(Just repeating my comment as the answer here)

The solution is to recursively call the cumsum function for each dimension:

`CDF = cumsum(ePDF,1); CDF = cumsum(CDF,2); CDF = cumsum(CDF,3); `