How to read a data from txt file: only a specific part of txt
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
serhat tekebas
am 13 Jun. 2018
Kommentiert: Paolo
am 14 Jun. 2018
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191233/image.jpeg)
Hi; I have a txt file as above.I want to get the value from marked section of txt and assign it to a variable.
4 Kommentare
Akzeptierte Antwort
Paolo
am 13 Jun. 2018
You can use regexp to match the sampling value. The expression below assumes that the character "E" is followed by a "-" character.
text = fileread('20171109_144634_14306_6O61N2.txt');
[match] = regexp(text,'(\d*\.\d*E-\d*)','match');
sampling = str2double(match{1});
sampling =
0.0050
7 Kommentare
Paolo
am 14 Jun. 2018
@serhat
If for some reason your time information changes position in the text file, text(191:203) will fail to extract that information. The regex pattern will find the data anywhere in the file.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!