필터 지우기
필터 지우기

How to select specific time frames from data?

조회 수: 9 (최근 30일)
Noah Poole
Noah Poole 2018년 10월 10일
댓글: Guillaume 2018년 10월 10일
I need to isolate the data between 7am-9am and 8pm-12am from a large set of 24-hour data that runs over a year. I'm not sure how to do this though because the first column, which contains the time data is structured as yyyy/mm/dd hh:mm:ss. Please see attached data. Could someone please help me on this? Currently in R2018a
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 10월 10일
An extract of the file format would help people who are working on their phone instead of a desktop....

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2018년 10월 10일
pickups = readtable('uber.csv');
pickuphours =hour(pickups.pickup_datetime);
filteredpickups = pickups(pickuphours >= 7 & pickuphours < 9 | pickuphours >= 20, :)
An alternative to that last line would be:
filteredpickups = pickups(ismember(pickuphours, [7 8 20 21 22 23]), :)

추가 답변 (1개)

Raúl GB
Raúl GB 2018년 10월 10일
You need to use the hour function if you are interested in a specified interval. You can do something like this to obtain the intervals, after loading the file properly:
[Interval1] = find(hour(pickup_datetime)>7 & hour(pickup_datetime)<9);
[Interval2] = find(hour(pickup_datetime)>20 & hour(pickup_datetime)<24);
Interval = [Interval1;Interval2];
Hope it helps.
  댓글 수: 1
Guillaume
Guillaume 2018년 10월 10일
Usually, find is completely unecessary and just slows things done. You could do:
interval1 = hour(pickup_datetime)>7 & hour(pickup_datetime)<9;
interval2 = hour(pickup_datetime)>20 & hour(pickup_datetime)<24;
interval = interval1 | interval2;
Note that hour(xxx)<24 is always going to be true. I'm also certain that 7 and 20 needs to be included in the set (so >= instead of >)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Install Products에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by