How to repeat data because of variables with two different timestamps?
1 view (last 30 days)
Show older comments
I have measured data with two different devices.
One device (Garmin device) measured data every second for about 20 minutes, so I have data with a 1207x1 format.
The other device (Cosmed device) measured data every 3 seconds (so 1, 4, 7, 10, etc.) also for about 20 minutes, so this results in a 470x1 format.
I want to compare variables measured from these devices, but for a reliable analysis I have to have the same time dimension (either per 1 or 3 seconds).
So...
Therefore, I want to repeat the data for 3 seconds three times, because this does not manipulate your data with interpolation or averaging (it's the best I can do I think in this situation).
What is the simplest way to achieve this?
3 Comments
Star Strider
on 2 Sep 2023
Not at all straightforward.
Torsten
on 2 Sep 2023
a = [1 2 3];
b = [1 5 8 2 9 12 7 5 16];
a3 = [];
for i = 1:numel(a)
a3 = [a3,a(i),a(i),a(i)];
end
a3
Accepted Answer
dpb
on 2 Sep 2023
Illustrate --
t=seconds(0:1:300).'; % one-second time series arbitrary length
tG=timetable(t,randn(size(t)),'VariableNames',{'Garmin'}); % create a 1-sec timetable
tC=timetable(t(1:3:end),randn(ceil(numel(t)/3),1),'VariableNames',{'Cosmed'}); % and another 3-sec
head(tC)
tC=retime(tC,'secondly','previous'); % convert the 3-sec to 1-sec by repeating sampled data
tGC=[tG tC]; % now put the two together
head(tGC)
With two files, you'll just read each and have the time vectors in them, I presume -- so read each and augment the shorter as needed...
5 Comments
dpb
on 3 Sep 2023
Yeah, retime is very flexible but it does require using a timetable to get access to it; it's understandable why is so, but would be handy if it could operate on regular datetime variables with auxiliary arrays--although it's generally not too inconvenient to just go ahead and create the needed timetable(s).
More Answers (0)
See Also
Categories
Find more on Time Series Events 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!