MATLAB: How to use linear interpolation on irregular intervals and reset value

irregular intervalslinear interpolation

[ 0 0 0 0 1 0 0 2 0 0 3 0 0 0 1 0 2 0 3 0 0 0 0 1 ]
result=>
[ 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.5 3 0 0.25 0.5 0.75 1 ]
Is there any helpful function for this?

Best Answer

data = [ 0 0 0 0 1 0 0 2 0 0 3 0 0 0 1 0 2 0 3 0 0 0 0 1 ];
match = (data ~= 0);
match([1, end]) = true;
result = interp1(find(match), data(match), find(~match))