Change Time and Time Format in Timetable

69 visualizzazioni (ultimi 30 giorni)
So I have this timetable called 'pleth' and I want to change the Record Time column. I have a starting point of '28-Apr-2022 22:02:11' and to that I want to add the seconds from the Record Time column.
Meaning, I want something like this:
28-Apr-2022 22:05:11
28-Apr-2022 22:05:21
28-Apr-2022 22:05:31
28-Apr-2022 22:05:41
... and so on.
I have tried this, but haven't had any success:
for i=1:size(pleth,1)
date=datetime(2022, 4, 28);
sec=seconds(pleth.Properties.RowTimes(i));
pleth.Properties.RowTimes(i) = date + duration(22, 2, 11+sec, 'Format', 'hh:mm:ss');
end
When I try this:
pleth.Properties.RowTimes(4) = duration(22, 02, 11 + seconds(pleth.Properties.RowTimes(4)), 'Format', 'hh:mm:ss')
The Time in row 4 changes, but the format is still in seconds. And the date still needs to be added.
Any help would be much appreciated!!

Risposta accettata

Cris LaPierre
Cris LaPierre il 15 Mag 2023
You can just create a datetime with your start time, and then add your record time to it.
Time = seconds(0:10:100)';
Data = rand(size(Time));
pleth = timetable(Time, Data)
pleth = 11×1 timetable
Time Data _______ ________ 0 sec 0.048138 10 sec 0.33276 20 sec 0.67083 30 sec 0.96782 40 sec 0.39506 50 sec 0.99582 60 sec 0.4327 70 sec 0.66247 80 sec 0.63188 90 sec 0.92561 100 sec 0.72182
startTime = datetime(2022,04,28,22,05,11)
startTime = datetime
28-Apr-2022 22:05:11
pleth.Time = pleth.Time + startTime
pleth = 11×1 timetable
Time Data ____________________ ________ 28-Apr-2022 22:05:11 0.048138 28-Apr-2022 22:05:21 0.33276 28-Apr-2022 22:05:31 0.67083 28-Apr-2022 22:05:41 0.96782 28-Apr-2022 22:05:51 0.39506 28-Apr-2022 22:06:01 0.99582 28-Apr-2022 22:06:11 0.4327 28-Apr-2022 22:06:21 0.66247 28-Apr-2022 22:06:31 0.63188 28-Apr-2022 22:06:41 0.92561 28-Apr-2022 22:06:51 0.72182
  1 Commento
Samuel
Samuel il 15 Mag 2023
Thanks for your quick answer. I'm still quite new to this. Have a great day!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by