Importing data from specific columns of a data structure

Hello all,
I am working on a large data file and want to extract the data for specific dates. The format of the file resembles the following:
Date Location Degree1 Degree2
20200101 NY 0 1
20200102 NY 0 0
20200103 NY 1 3
Now what if I want to extract all the data from 20200101 to 20200103?

 Respuesta aceptada

T = readtable('data.txt')
T = 6×4 table
Date Location Degree1 Degree2 ________ ________ _______ _______ 2.02e+07 {'NY'} 0 1 2.02e+07 {'NY'} 0 0 2.02e+07 {'NY'} 1 3 2.02e+07 {'NY'} 1 9 2.02e+07 {'NY'} 2 7 2.02e+07 {'NY'} 2 6
T(T.Date >= 20200101 & T.Date <= 20200103,:)
ans = 3×4 table
Date Location Degree1 Degree2 ________ ________ _______ _______ 2.02e+07 {'NY'} 0 1 2.02e+07 {'NY'} 0 0 2.02e+07 {'NY'} 1 3

3 comentarios

It may be convenient to work with datetime dates
T = readtable('data.txt');
T.Date = datetime(T.Date,'ConvertFrom','yyyymmdd')
T = 6×4 table
Date Location Degree1 Degree2 ___________ ________ _______ _______ 01-Jan-2020 {'NY'} 0 1 02-Jan-2020 {'NY'} 0 0 03-Jan-2020 {'NY'} 1 3 04-Jan-2020 {'NY'} 1 9 05-Jan-2020 {'NY'} 2 7 06-Jan-2020 {'NY'} 2 6
T(T.Date >= '01-Jan-2020' & T.Date <= '03-Jan-2020',:)
ans = 3×4 table
Date Location Degree1 Degree2 ___________ ________ _______ _______ 01-Jan-2020 {'NY'} 0 1 02-Jan-2020 {'NY'} 0 0 03-Jan-2020 {'NY'} 1 3
T(T.Date >= '2020-01-01' & T.Date <= '2020-01-03',:)
ans = 3×4 table
Date Location Degree1 Degree2 ___________ ________ _______ _______ 01-Jan-2020 {'NY'} 0 1 02-Jan-2020 {'NY'} 0 0 03-Jan-2020 {'NY'} 1 3
T(T.Date >= 'Jan 01, 2020' & T.Date <= 'Jan 03, 2020',:)
ans = 3×4 table
Date Location Degree1 Degree2 ___________ ________ _______ _______ 01-Jan-2020 {'NY'} 0 1 02-Jan-2020 {'NY'} 0 0 03-Jan-2020 {'NY'} 1 3
This helps a lot; thank you so much.
Voss
Voss el 26 de Jun. de 2022
Editada: Voss el 26 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 25 de Jun. de 2022

Editada:

el 26 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by