Averaging non-aligned time-series arrays
Show older comments
I have four arrays of time series data, sampled at equal intervals. The arrays do not start or end at the same times. So I have eight arrays (time values are integers):
- time1, data1
- time2, data2
- time3, data3
- time4, data4
How can I create a mean time series from all four, covering the entire time range? I would assume NaN where there is no data.
For example, with two small time series:
time1 = [1 2 3 4];
data1 = [1 1 1 1];
time2 = [3 4 5];
data2 = [3 3 3];
I want the result:
timeMean = [1 2 3 4 5];
dataMean = [1 1 2 2 3]
I could do this with several loops, but is there an elegant way?
Accepted Answer
More Answers (2)
dormant
on 8 Oct 2024
0 votes
Steven Lord
on 8 Oct 2024
0 votes
If those integer arrays represent some amount of time (seconds since the start of whatever experiment you used to collect the data, for example) consider creating a duration array out of them (in that scenario I described above I'd use the seconds function) and using that duration array to create a timetable. If you do you can retime or synchronize to change the time basis of the timetable.
Categories
Find more on Data Import and Analysis 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!