%% Vector with NaN Values
% Create a vector containing NaN values and compute the cumulative products. By default, cumprod includes NaN values. When you include NaN values in the calculation, the cumulative product becomes NaN as soon as the first NaN value in A is encountered.

A = [1 3 NaN 2 4 NaN];
B = cumprod(A)

%
% Ignore NaN values in the cumulative product calculation using the 'omitnan' option.

B = cumprod(A,'omitnan')

% Copyright 2012 The MathWorks, Inc.