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

조회 수: 5 (최근 30일)
serhat tekebas
serhat tekebas 2018년 6월 13일
댓글: Paolo 2018년 6월 14일
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일
Please attach the text file and not the screenshot.

댓글을 달려면 로그인하십시오.

채택된 답변

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