reading text fils with data importing
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Stephen23
le 26 Fév 2025
Modifié(e) : Stephen23
le 26 Fév 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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!