%% Vector with NaN Values
% Create a vector containing NaN values and compute the cumulative maxima. By default, cummax ignores NaN values.

A = [3 5 NaN 9 0 NaN];
M = cummax(A)

%
% If you include NaN values in the calculation, then the cumulative maximum becomes NaN as soon as the first NaN value in A is encountered.

M = cummax(A,'includenan')

% Copyright 2012 The MathWorks, Inc.