Azzera filtri
Azzera filtri

filtering a table with dates

4 visualizzazioni (ultimi 30 giorni)
AA
AA il 25 Set 2015
Commentato: Walter Roberson il 27 Set 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

Risposte (1)

Walter Roberson
Walter Roberson il 25 Set 2015
Modificato: Walter Roberson il 27 Set 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 Commenti
AA
AA il 27 Set 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 il 27 Set 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,:);

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by