How to extract the following number from a text file?
Show older comments
Dear memebers,
Can you please help me extract the following number hilighted in yellow from a text file into MATLAB?
The numbers will change each time but other characters will stay the same.
You can find the text file attached and that number will be at the end of the text.
Thank you!

Accepted Answer
More Answers (1)
Walter Roberson
on 23 Apr 2019
Edited: Walter Roberson
on 24 Apr 2019
filename = 'output_matlab.txt';
S = fileread(filename);
phd_str = regexp(S, '(?<=^Pile-head deflection\s+=\s+)\S+', 'match', 'lineanchors');
phd = str2double(phd_str);
This code will find any Pile-head deflection value that is in the file. If you are sure that there is only one in the file, then you can add the option 'once' to the regexp() call to speed up execution.
2 Comments
Ahmad Fakih
on 23 Apr 2019
Walter Roberson
on 24 Apr 2019
I made a silly typing mistake when I copied the code in from what I had tested. I have fixed it now in what I posted.
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!