How to use linear interpolation on irregular intervals and reset value

[ 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?

2 commentaires

Hyowon - is there any pattern to the above? Does the 1,2,3 repeat with only the number of zeros changing between non-zero integer?
Hyowon Lee
Hyowon Lee le 18 Nov 2015
Modifié(e) : Hyowon Lee le 18 Nov 2015
Geoff, That's all.
The only differences are the length of data and reset value.
[ 0 0 0 1 0 0 2 0 0 3 0 0 0 4 ..... 720 0 0 1 0 0 2 0 0 0 3 .. ]

Connectez-vous pour commenter.

 Réponse acceptée

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))

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by