Change Time and Time Format in Timetable

72 vues (au cours des 30 derniers jours)
Samuel
Samuel le 15 Mai 2023
Commenté : Samuel le 15 Mai 2023
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!!

Réponse acceptée

Cris LaPierre
Cris LaPierre le 15 Mai 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 commentaire
Samuel
Samuel le 15 Mai 2023
Thanks for your quick answer. I'm still quite new to this. Have a great day!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by