converting and comparing 24hr cell to a minimum value
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hoping to convert a string called "adjTIB" from a 24 hour cell ie. 14:11 to compare whether it is > 21:00, and < 09:00
I assume I need to run a cellfun to compare inequality to a constant, but not sure if there is an easier way.
0 commentaires
Réponse acceptée
Adam Danz
le 13 Jan 2020
"Hoping to convert a string called "adjTIB" from a 24 hour cell ie. 14:11 "
This is a bit ambiguous. Does the cell array contain strings? Datetime values? Durations? If what format? Provide an example or detailed description and I'd be glad to help out with that step.
" compare whether [the values are] > 21:00, and < 09:00 "
A time or duration cannot be greater than 21:00 and less than 9:00 at the same time. I'm guessing that you want to identify times or durations that are less than 9:00 or greater than 21:00. First convert the values in your cell array to either durations or datetime. This isn't an arbitrary choice; chose the format that describe your data.
d = datetime(1999,03,16):minutes(15):datetime(1999,03,17);
idx = hour(d) > 21 | hour(d) < 9;
... or Durations
d = hours(rand(1,20)*24);
idx = d > hours(21) | d < hours(9);
2 commentaires
Adam Danz
le 13 Jan 2020
" its much simpler to handle and manipulate the original datetime variable"
Yes! That will almost always be the case. I take it the problem is solved, then. Let me know if there are any leftover problems.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!