필터 지우기
필터 지우기

Extracting a double from a text file

조회 수: 11 (최근 30일)
Rica
Rica 2021년 5월 28일
댓글: Mathieu NOE 2021년 5월 31일
Hi everone,
I want to extract the number that in front of Volt[M/Y] from alarge Text file. the structure of the file is described bellow. After reading the files in matlab, i want to look for the numbers in front of Volt [M/Y]. I succeded reading the files, and i also tried to solve the task with the matlab function regexp:
Data= regexp(A,'M/Y]\s*\w*$','tokens');
I have a dificulty to write the aproppriate expression to save the right number. Could you plase give any hints?
Thank you
U I N
2.420 -28.87 3.0710
2.430 -30.82 2.1945
Volt [M/Y] -12.258812
U I N
700 -30.39 1.9684
900 -29.60 2.1034
Volt [M/Y] 100.05

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 5월 28일
hello
my 2 cents suggestion (as I still struggle with regexp !)
bs = split(fileread('data.txt'));
values = bs(find(strcmp(bs,'[M/Y]')>0) + 1);
  댓글 수: 2
Rica
Rica 2021년 5월 28일
Thank you Mathieu. Great way to solve it. I learnt something new!
Mathieu NOE
Mathieu NOE 2021년 5월 31일
My pleasure
still have to workout regexp !!

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

추가 답변 (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