MATLAB: How to use cumsum + interp1q on reset values.

cumsuminterp1qreset

[ 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 ]
cumsum with reset '3' value and delete repeated values
[ 0 0 0 0 1 0 0 2 0 0 3 0 0 0 1 0 2 0 3 0 0 1 0 0 2 0 0 3 0 0 0 1]
interp1q to fill in 0s
[ 0 0.25 0.5 0.75 1 1.33 1.67 2 2.33 2.67 3 0.33 0.67 1 1.33 1.67 2 2.33 2.67 3 0 0.25 0.5 0.75 1 ]
I tried several ways.., but I can't find a way.

Best Answer

A = [ 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 ];
C = mod((1:sum(A)) - 1, 3) + 1; cumsum with reset '3' value and delete repeated values
newA = 0 * A;
newA( logical(A) ) = C;
and now do your interpolation. However, you cannot use interp1() because interp1() would use the 3's as the basis of interpolation rather than resetting to 0.