Extracting a number from certain line of .txt file

조회 수: 1 (최근 30일)
Mohammad Mirza Hassan
Mohammad Mirza Hassan 2018년 6월 19일
댓글: Mohammad Mirza Hassan 2018년 6월 19일
Hi everyone I have big .txt file and I want to extract the certain value
How can I extract and print the value written after "COLLAPSE MULTIPLIER=" into file.
  댓글 수: 2
KSSV
KSSV 2018년 6월 19일
Attach your text file...image snippets will not allow us to copy and try it.
Mohammad Mirza Hassan
Mohammad Mirza Hassan 2018년 6월 19일
편집: Mohammad Mirza Hassan 2018년 6월 19일
Hope this helps now. Thank you

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

채택된 답변

Paolo
Paolo 2018년 6월 19일
For the values which follow "COLLAPSE MULTIPLIER = ", you can simply use a positive lookbehind which checks for the pattern you indicated.
file = fileread('collapsemultiplier.txt');
match = regexp(file,'(?<=COLLAPSE\sMULTIPLIER\s=\s)(\d*.?\d*)','match');
match =
1×10 cell array
Columns 1 through 6
{'1.945'} {'3.594'} {'4.648'} {'5.361'} {'5.898'} {'6.360'}
Columns 7 through 10
{'6.727'} {'7.038'} {'7.337'} {'7.584'}
You can play around with it here.
  댓글 수: 7
Paolo
Paolo 2018년 6월 19일
Try opening the .txt file in Notepad ++.
Mohammad Mirza Hassan
Mohammad Mirza Hassan 2018년 6월 19일
Working perfect in Notepad++ .Cheers

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by