フィルターのクリア

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 Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by