Extracting a number from certain line of .txt file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad Mirza Hassan
le 19 Juin 2018
Commenté : Mohammad Mirza Hassan
le 19 Juin 2018
Hi everyone I have big .txt file and I want to extract the certain value
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191347/image.png)
How can I extract and print the value written after "COLLAPSE MULTIPLIER=" into file.
2 commentaires
Réponse acceptée
Paolo
le 19 Juin 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'}
7 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!