How to read a data from txt file: only a specific part of txt

5 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Paolo
Paolo 2018-6-13
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 个评论
serhat tekebas
serhat tekebas 2018-6-14
what is the difference between your solution and
text = fileread('20171109_144634_14306_6O61N2.txt');
timevar=text(191:203)
Paolo
Paolo 2018-6-14
@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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by