Read .txt file in matlab and save date
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
elisa ewin
el 24 de Mayo de 2016
Comentada: Star Strider
el 24 de Mayo de 2016
Hi! I have a file .txt with this data:
user check-in time (year-month-day hours) latitude longitude location id
0 2010-10-03 22-21-49 30.2448597206 -97.7571630478 18417
0 2010-10-02 01-48-43 30.2558143993 -97.7634179592 4256132
0 2010-10-01 14-36-39 30.2679095833 -97.7493124167 21714
0 2010-09-30 23-23-22 30.2643362697 -97.7410461251 211286
0 2010-09-29 00-31-24 30.2379105 -97.79996073 539065
0 2010-09-28 23-47-07 30.2313745667 -97.79745475 15590
0 2010-09-27 14-52-01 30.2691029532 -97.7493953705 420315
0 2010-09-26 16-43-45 30.250617981 -97.7658996582 121955
0 2010-08-30 00-11-01 30.2509939667 -97.7489662167 9508
0 2011-08-28 22-27-57 30.2448597206 -97.7571630478 18417
I want read this file in matlab and I want to save in a variable A only the rows with year 2010 and months 10 and 8, can you help me?
0 comentarios
Respuesta aceptada
Star Strider
el 24 de Mayo de 2016
You have to re the entire file into our workspace, then select the rows you want.
It is probably easiest to use the textscan function to read it.
For example:
fidi = fopen( ..., 'rt');
d = textscan(fidi, '%f %s %s %f %f %f', 'HeaderLines',1, 'CollectOutput',true);
The ‘d’ variable will be a cell array with the second and third columns as cell arrays of strings.
Another possibility is:
d = textscan(fidi, '%f %f-%f-%f %f-%f-%f %s %f %f %f', 'HeaderLines',1, 'CollectOutput',true);
NOTE — This is UNTESTED CODE. I do not have your file to test it with.
2 comentarios
Star Strider
el 24 de Mayo de 2016
Depending on how your read them in, use logical tests to isolate the rows for year 2010 and the months 8 and 10. Without your file to work with, I cannot be more specific.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Export en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!