converting and comparing 24hr cell to a minimum value

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.

 Risposta accettata

"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.
Here's how to do that with Datetime values
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 Commenti

You're correct, I did mean greater than 9 pm and earlier than 9 am, looking for the indices that include values within that range. I apologize
Originally, the data is in the form of a datetime variable to which I converted using datestr
datestr(InBedTime(i,5),15)
% converts to an output of HH:MM in 24Hr format
But looking at your advice, its much simpler to handle and manipulate the original datetime variable. Using your code, I can identify the indices that fall within the 9 pm - 9 am range, and analyze that data.
thanks for your help.
" 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.

Accedi per commentare.

Più risposte (0)

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by