Borrar filtros
Borrar filtros

filtering a table with dates

4 visualizaciones (últimos 30 días)
AA
AA el 25 de Sept. de 2015
Comentada: Walter Roberson el 27 de Sept. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Sept. de 2015
Editada: Walter Roberson el 27 de Sept. de 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 comentarios
AA
AA el 27 de Sept. de 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 el 27 de Sept. de 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,:);

Iniciar sesión para comentar.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by