How to fill in gaps of multiple data vectors according to time vector

1 view (last 30 days)
Hi.
I have a bunch of vectors containing data and a timestamp with the respective time the data was recorded. I want the data vectors to show data for every 12 seconds. However, some of the data is missing (max for 48 seconds / 4 values in a row). So what I want to do is fill in the gaps in the data vectors with the value that was last recorded.
I have extracted the "second" values from the time stamp and created another vector containing the values the timestamp would have if there were no gaps:
%the "real" "second" values:
Seconds = [0; 12; 24; 24; 36; 48; 0; 12; 36;...]
%the "optimal" "second" values:
optSeconds = [0; 12; 24; 36; 48; 0; 12; 24; 36; 48; 0; 12; 24;...]
There are 48 seconds (or 4 data values) missing between Seconds(3) and Seconds(4), for example. So if the first data vector is:
Data = [510; 200; 100; 324;...]
I want to change it to:
optData = [510; 200; 100; 100; 100; 100; 100; 324; ...]
I would be really grateful for any suggestions how to do this efficiently. I have made some attempts comparing the two time stamps in loops, but so far the calculations have taken over an hour, because the time stamp goes on for a month (the "optimal" time stamp is a 222905x1 double).

Answers (0)

Community Treasure Hunt

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

Start Hunting!