how to select time which comes in a range from cell array

if i have a time as
cellArr = {'6:25:48'
'7:28:18'
'8:30:20'
'9:32:37'
'10:35:40'};
how to select time which comes in a range? eg: time between 7:00:00 and 9:00:00
7:28:18
8:30:20

 採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 25 日
編集済み: Walter Roberson 2017 年 2 月 26 日

1 投票

Convert to datetime objects and then use

4 件のコメント

Guillaume
Guillaume 2017 年 2 月 25 日
編集済み: Guillaume 2017 年 2 月 25 日
Walter wrote:
Convert to datetime objects and then use isbetween
The first half of the sentence is as important as the second half.
The conversion to datetime would be achieved with
d = datetime(cellArr, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss')
Elysi Cochin
Elysi Cochin 2017 年 2 月 25 日
sir i did as you said
t = datetime(cellArr);
now as i dont have date the current date is coming in the date column...
'25-Feb-2017 06:25:48'
'25-Feb-2017 07:28:18'
'25-Feb-2017 08:30:20'
'25-Feb-2017 09:32:37'
'25-Feb-2017 10:35:40'
is there any way i can remove the date and keep only the time...
Guillaume
Guillaume 2017 年 2 月 25 日
You may have written your comment as I edited mine. Use the 'Format' property of the datetime object to make it display as you want.
t = datetime(cellArr, 'Format', 'hh:mm:ss')
Walter Roberson
Walter Roberson 2017 年 2 月 26 日
You also might want to consider using duration objects:
cellArr = {'6:25:48'
'7:28:18'
'8:30:20'
'9:32:37'
'10:35:40'};
temp = regexp(cellArr, ':', 'split');
durations = duration(str2double(vertcat(temp{:})));
low = hours(7);
high = hours(9);
durations(durations >= low & durations <= high)

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by