필터 지우기
필터 지우기

Delete rows if the column has weekend date

조회 수: 2 (최근 30일)
Trung Hieu Le
Trung Hieu Le 2016년 6월 17일
답변: Peter Perkins 2016년 8월 3일
Hi everyone,
I have data as follows:
- first column: date (mm/dd/yyyy)
- second column: time
- third column: price
How can I delete the row if the column date is Saturday, Sunday and holiday? Ex:
01/02/1996 10:00:00 17.48
01/03/1996 10:30:00 17.46
01/04/1996 11:00:00 17.46
01/05/1996 11:30:00 17.47
01/06/1996 12:00:00 17.47
01/07/1996 12:30:00 17.48
01/08/1996 13:00:00 17.48
01/09/1996 13:30:00 17.48
01/10/1996 14:00:00 17.49
01/11/1996 14:30:00 17.48
01/12/1996 15:00:00 17.52
01/13/1996 15:30:00 17.52
Thanks a lot for your help

답변 (1개)

Peter Perkins
Peter Perkins 2016년 8월 3일
'date' and 'time' aren't really types in MATLAB, so it's not clear what you have. I'm guessing you have a cell array, the first column of which contains date strings, the second time strings, the third numbers. That's probably not what you want.
c = { ...
'01/02/1996' '10:00:00' 17.48
'01/03/1996' '10:30:00' 17.46
'01/04/1996' '11:00:00' 17.46
'01/05/1996' '11:30:00' 17.47
'01/06/1996' '12:00:00' 17.47
'01/07/1996' '12:30:00' 17.48
'01/08/1996' '13:00:00' 17.48
'01/09/1996' '13:30:00' 17.48
'01/10/1996' '14:00:00' 17.49
'01/11/1996' '14:30:00' 17.48
'01/12/1996' '15:00:00' 17.52
'01/13/1996' '15:30:00' 17.52};
DateTime = datetime(strcat(c(:,1),{' '},c(:,2)));
Value = cell2mat(c(:,3))
t = table(DateTime,Value)
t2 = t(~isweekend(t.DateTime),:)
From which I get
t2 =
DateTime Value
____________________ _____
02-Jan-1996 10:00:00 17.48
03-Jan-1996 10:30:00 17.46
04-Jan-1996 11:00:00 17.46
05-Jan-1996 11:30:00 17.47
08-Jan-1996 13:00:00 17.48
09-Jan-1996 13:30:00 17.48
10-Jan-1996 14:00:00 17.49
11-Jan-1996 14:30:00 17.48
12-Jan-1996 15:00:00 17.52
Holidays, you're on your own. They are different in every country. Make a list of them, use ismember to find them in t.DateTime.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by