convert 12 hour data to 24 hour datetime data for timetable
Mostra commenti meno recenti
I have a data table with the first 3 variables corresponding to the date/time. I would like to convert the date time variables to
'yyy-MM-dd hh:mm:ss' data like I have for my other timetable. I'm just confused on how to efficiently convert this. In the images attached, the raw image is the table from my data txt file and desired is the desired timetable format.
Risposta accettata
Più risposte (2)
Once imported, you could query the AM/PM column, and if the answer is PM, add 12 hours to the value, and then delete the AM/PM column from the table.
Borrowing the windspeed example table:
MeasurementTime = datetime({'2015-12-18 08:03:05';'2015-12-18 10:03:17';'2015-12-18 12:03:13'});
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
AMPM = cellstr(['AM';'PM';'AM']);
TT = timetable(MeasurementTime,Temp,Pressure,WindSpeed,AMPM)
G = findgroups(TT.AMPM) % Ordered alphabetically, so PM is G ==2
TT.MeasurementTime(G==2,:) = TT.MeasurementTime(G==2,:) + hours(12)
TT.AMPM = [] % Drop AMPM field.
1 Commento
Poison Idea fan
il 16 Mar 2022
talha iqbal
il 26 Mag 2023
Modificato: talha iqbal
il 26 Mag 2023
0 voti
What about Noon (12PM) or Midnight (12AM) ?
1 Commento
Poison Idea fan
il 31 Mag 2023
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!