How to repeat data because of variables with two different timestamps?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 2 Set 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
a3 = 1×9
1 1 1 2 2 2 3 3 3

Accedi per commentare.

Risposta accettata

dpb
dpb il 2 Set 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)
Time Cosmed ______ ________ 0 sec 0.30895 3 sec -0.34037 6 sec 1.6222 9 sec 0.63342 12 sec -0.2297 15 sec -0.2933 18 sec -0.72891 21 sec 0.50354
tC=retime(tC,'secondly','previous'); % convert the 3-sec to 1-sec by repeating sampled data
tGC=[tG tC]; % now put the two together
Time Cosmed _____ ________ 0 sec 0.30895 1 sec 0.30895 2 sec 0.30895 3 sec -0.34037 4 sec -0.34037 5 sec -0.34037 6 sec 1.6222 7 sec 1.6222
head(tGC)
t Garmin Cosmed _____ ________ ________ 0 sec 0.099782 0.30895 1 sec 0.68994 0.30895 2 sec 0.8777 0.30895 3 sec 1.8498 -0.34037 4 sec -0.55117 -0.34037 5 sec 1.3509 -0.34037 6 sec -0.35978 1.6222 7 sec -0.51248 1.6222
See retime for details on its features.
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 Commenti
Ilse Frans
Ilse Frans il 3 Set 2023
Got to fix it using the following code:
garmin_t_new = seconds(0:1:1206).';
tG = timetable(garmin_t_new,garmin_EE_HR,garmin_VO2_HR,garmin_MET_HR,garmin_EE_GPS,garmin_VO2_GPS,garmin_MET_GPS,'VariableNames',{'EE_HR','VO2_HR','MET_HR','EE_GPS','VO2_GPS','MET_GPS'}); % create Garmin timetable
cosmed_t_new = duration(cosmed_t,'InputFormat','mm:ss');
tC = timetable(cosmed_t_new,cosmed_EEm,cosmed_VO2kg,cosmed_METs,'VariableNames',{'EEm','VO2','METs'}); % create Cosmed timetable
tC = retime(tC,garmin_t_new,'previous');
dpb
dpb il 3 Set 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).

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by