import and sorting text file to matlab
Mostrar comentarios más antiguos
hi all.
I have these hundreds text files with some data i should analyze
each file has date column time column, ID column and value column.
i would like to create a structure that contains text file name and ID as fields and then fill it with the respectvie times and values. i wpould like to create a general code that can be used in every future situation, because i'm going to get more and more of this text files to analyze.
7 comentarios
Guillaume
el 13 de Mzo. de 2019
Can you attach an example text file?
Is there only one ID per file? It's not clear what output you want. Can you show an example of what you want (preferably using valid matlab syntax so it's not ambiguous).
nicolala
el 13 de Mzo. de 2019
nicolala
el 13 de Mzo. de 2019
Guillaume
el 13 de Mzo. de 2019
"an ID has different value size from the same ID in another file."
You mean the number of rows varies from file to file? Or something else?
I'm still unsure of what you want. You want to create just one output for all the files, where all the IDs and times are all in one array with an extra column for the file, then sort by ID and time? Or have one array per file, each one sorted?
From a parsing point of view, it would be much easier if the date was stored as 2019-02-19 (or 2019/02/19, or anything but spaces between the number). Is that an option?
nicolala
el 13 de Mzo. de 2019
What does "each ID has different rows" mean?
In your example file, each ID, except ID 0, is only present on one or two rows. ID 0 must have a special meaning since it's repeated so often.
Importing your file is trivial
t = mergevars(readtable('example.txt'), 1:3);
t.Properties.VariableNames = {'Date', 'Time', 'ID', 'something'};
t.Date = datetime(t.Date)
Sorting by ID and time is also trivial:
sortrows(t, {'ID', 'Time'})
I'm really struggling to understand what needs to be done afterwards.
nicolala
el 13 de Mzo. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


