How to use cumsum + interp1q on reset values.

3 views (last 30 days)
[ 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.
  1 Comment
Hyowon Lee
Hyowon Lee on 18 Nov 2015
is there any function to fill in the 0s? (because interp1q could not be used for this)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Nov 2015
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.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!