Summing Datenum resets after 24 hours
Mostra commenti meno recenti
Hello all,
I am trying to sum datenum values, and return them to hours:mins:secs format when all complete. When the amount of time is relatively small, it works as expected, but once it rolls past 24 hours, it resets.
Example:
a = datenum('21:10:00','hh:MM:ss')
b = datenum('1:10:00','hh:MM:ss')
c = datestr(x+y,'hh:MM:ss')
c = '22:20:00'
x = datenum('21:10:00','hh:MM:ss')
y = datenum('7:10:00','hh:MM:ss')
z = datestr(x+y,'hh:MM:ss')
z = '04:20:00'
Anyone know how to get around that to output :
z = '28:10:00'
and also 3 digit hours if need-be.
Any help is greatly appreciated!
Risposta accettata
Più risposte (2)
Matt Gaidica
il 15 Dic 2020
I don't know if the datetime functions are going to allow that triple digit hour. Here's one approach.
z = sprintf('%03i:%02i:%02i',hour(x) + hour(y), minute(x+y), second(x+y))
Serial date numbers are not the right tool for this job. You want to use a duration array.
dur1 = duration(12, 23, 45)
dur2 = hours(67)+minutes(89)
D = dur1 + dur2
If you want you can control the display Format.
D.Format = 'h'
1 Commento
Ruger28
il 15 Dic 2020
Categorie
Scopri di più su Time Series Objects 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!