Effacer les filtres
Effacer les filtres

filtering a table with dates

4 vues (au cours des 30 derniers jours)
AA
AA le 25 Sep 2015
Commenté : Walter Roberson le 27 Sep 2015
I have a table with 3 columns. COLUMN one has a serial date number. Column two has the time and column three has a value. I want to filter the table so that I got only serial date numbers in the range of 23. September 2015, 3 pm to 24. September 2015, 5 pm, 3. june 2014, 4 pm to 5. June 2014, 7 pm.
thanks for your help

Réponses (1)

Walter Roberson
Walter Roberson le 25 Sep 2015
Modifié(e) : Walter Roberson le 27 Sep 2015
datelimstr = {'23. September 2015, 3 pm', '24. September 2015, 5 pm', '3. june 2014, 4 pm', '5. June 2014, 7 pm'};
datelim = datenum(datelimstr, 'DD mmmm YYYY, HH PM');
SD = YourTable.SerialDate;
inrange = (SD >= datelim(1) & SD <= datelim(2)) | (SD >= datelim(3) & SD <= datelim(4));
SubTable = YourTable(inrange,:);
This presumes that the "serial date number" includes the time in it and not just the integer part. If not then we need to know what the format is for the time column.
  2 commentaires
AA
AA le 27 Sep 2015
it doesnt work, i get a table with zeros. can you redefine the code without the time column. i deleted the time column. i only need the date. thanks
Walter Roberson
Walter Roberson le 27 Sep 2015
I had a typo, but otherwise it should have worked, provided the date strings were in the format you posted, complete with commas and period. Anyhow, without the time information:
datelimstr = {'23. September 2015', '24. September 2015', '3. june 2014', '5. June 2014'};
datelim = datenum(datelimstr, 'DD. mmmm YYYY');
SD = YourTable.SerialDate;
inrange = (SD >= datelim(1) & SD <= datelim(2)) | (SD >= datelim(3) & SD <= datelim(4));
SubTable = YourTable(inrange,:);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables 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