www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CumsumVectorWithNaNValuesExample.m
%% Vector with |NaN| Values % Create a vector containing |NaN| values and compute the cumulative % sums. By default, |cumsum| includes |NaN| values. When you include % |NaN| values in the calculation, the cumulative sum becomes |NaN| as soon % as the first |NaN| value in |A| is encountered. A = [3 5 NaN 9 0 NaN]; B = cumsum(A) %% % You can ignore |NaN| values in the cumulative sum calculation using % the |'omitnan'| option. B = cumsum(A,'omitnan')