Effacer les filtres
Effacer les filtres

Delete rows if the column has weekend date

2 vues (au cours des 30 derniers jours)
Trung Hieu Le
Trung Hieu Le le 17 Juin 2016
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

Réponses (1)

Peter Perkins
Peter Perkins le 3 Août 2016
'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.

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by