%% Cumulative Maximum Array Values in Reverse Direction
% Calculate the cumulative maxima in the third dimension of a 2-by-2-by-3 array. Specify direction as 'reverse' to work from the end of the third dimension to the beginning.

A = cat(3,[1 2; 3 4],[9 10; 11 12],[5 6; 7 8])

%

M = cummax(A,3,'reverse')

% Copyright 2012 The MathWorks, Inc.