MATLAB Answers

0

select data from table according to date and time

Asked by MOMO JOJO on 26 Mar 2019
Latest activity Commented on by Peter Perkins
on 2 Apr 2019
Hallo,
I need your help for matlab.
I have a table with dates and times data for 7 days. I want to select records between 14:00 to 16:00 for each day?!
Thanks

  2 Comments

Are the times in a separate variable in the table, or do you have a single datetime column?
If the times are in a separate variable in the table, then what format are they in?
Dear Walter,
The times are in the same table. Some of data are mentionned bellow. They are for 7 days
'08-Feb-2019 11:03:40'
'08-Feb-2019 11:08:40'
'08-Feb-2019 11:13:40'
'08-Feb-2019 11:18:40'
Thanks

Sign in to comment.

1 Answer

Answer by Akira Agata
on 27 Mar 2019

How about the following way?
% Create sample data
Time = sort(datetime(2019,3,24) + days(7)*rand(1000,1));
Data = rand(1000,1);
T1 = table(Time,Data);
% Select records (row index) between 14:00 to 16:00
idx = (T1.Time.Hour >= 14) & (T1.Time.Hour) < 16;
% Extract selected records
T2 = T1(idx,:);

  5 Comments

Thank you, Walter-san !
Thanks dears Walter-san & Akira Agata,
For your grand help.
isbetween would probably make this more manageable:
>> isbetween(timeofday(datetime),'14:00:00','16:30:00')
ans =
logical
1

Sign in to comment.