reading text fils with data importing
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
UWM
el 26 de Feb. de 2025
Comentada: UWM
el 27 de Feb. de 2025
I have a long text file with data. There are "epochs" starting with EP and "information" i few next lines like that:
EP 00 00 00
G03
F17
D32
EP 00 00 30
G01
F04
D31
G03
H34
EP 00 01 00
B34
K05
L22
H34
H11
G11
EP 00 01 30
H90
G03
EP...
I need to read all epochs and if in a given epoch there will be a line with information of my choice, containing, for example "G03" I need confirmation this e.g. as "1" and if these information is not at epoch confirmation as e.g. "0". The are two problems from my point of view: there could be different number of lines with "information" in particular epochs and "information" of my choice may lie in any line.
Thank you in advance for any suggestions
0 comentarios
Respuesta aceptada
Stephen23
el 26 de Feb. de 2025
Editada: Stephen23
el 26 de Feb. de 2025
It would be much better if you uploaded a sample data file by clicking the paperclip button.
In lieu of that I created my own demo data file:
str = fileread('myfile.txt')
tkn = regexp(str,'EP(\s+\d+){3}(\s+[A-Z]\d+)+','tokens');
tkn = vertcat(tkn{:});
spl = regexp(tkn(:,2),'\w+','match');
uni = unique([spl{:}]);
drn = duration(sscanf([tkn{:,1}],'%u',[3,Inf]).')
fnh = @(t)contains(uni,t);
tmp = cellfun(fnh,spl,'uni',0);
tmp = vertcat(tmp{:});
tbl = array2timetable(tmp, 'RowTimes',drn, 'VariableNames',uni)
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files 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!