Filter löschen
Filter löschen

Extracting a number from certain line of .txt file

1 Ansicht (letzte 30 Tage)
Mohammad Mirza Hassan
Mohammad Mirza Hassan am 19 Jun. 2018
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 Kommentare
KSSV
KSSV am 19 Jun. 2018
Attach your text file...image snippets will not allow us to copy and try it.
Mohammad Mirza Hassan
Mohammad Mirza Hassan am 19 Jun. 2018
Bearbeitet: Mohammad Mirza Hassan am 19 Jun. 2018
Hope this helps now. Thank you

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Paolo
Paolo am 19 Jun. 2018
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 Kommentare
Paolo
Paolo am 19 Jun. 2018
Try opening the .txt file in Notepad ++.
Mohammad Mirza Hassan
Mohammad Mirza Hassan am 19 Jun. 2018
Working perfect in Notepad++ .Cheers

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings 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!

Translated by