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.

 採用された回答

Adam Danz
Adam Danz 2020 年 1 月 13 日

1 投票

"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 件のコメント

Noah Milman
Noah Milman 2020 年 1 月 13 日
編集済み: Noah Milman 2020 年 1 月 13 日
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.
Adam Danz
Adam Danz 2020 年 1 月 13 日
" 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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

質問済み:

2020 年 1 月 13 日

コメント済み:

2020 年 1 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by