If I have a vector of either 1's or NaN's like this:
[1 1 1 NaN 1 1 NaN 1 1 1 1]
How can I reset the cumsum to zero at the location of the NaNs like below:
[1 2 3 0 1 2 0 1 2 3 4]
Ideally I would like to have a vectorized solution since I need to do this for every column in a large matrix and the locations of the NaNs are not constant across the columns.
Thanks in advance.