1function A = cumsumnan(a)
2
3% Copyright (C) 2016 Dynare Team
4%
5% This code is free software: you can redistribute it and/or modify
6% it under the terms of the GNU General Public License as published by
7% the Free Software Foundation, either version 3 of the License, or
8% (at your option) any later version.
9%
10% Dynare dseries submodule is distributed in the hope that it will be useful,
11% but WITHOUT ANY WARRANTY; without even the implied warranty of
12% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13% GNU General Public License for more details.
14%
15% You should have received a copy of the GNU General Public License
16% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
17
18b = ~isnan(a);
19A = a;
20
21for i=1:size(a, 2)
22    c = find(b(:,i), 1);
23    A(c:end,i) = cumsum(a(c:end,i));
24end