Extracting number from output file
이전 댓글 표시
Hello,
I'm trying to extract a number from a large text file. The line I'm looking for looks something like this:
SCF Done: E(RB3LYP) = -78.5770732414 A.U. after 9 cycles
How would I extract "-78.5770732414" using fscan or textscan?
Thanks in advance for your help!
-Jim
답변 (1개)
>> buffer = fileread('data.txt') ;
>> loc = strfind(buffer, 'SCF Done: E(RB3LYP)') ;
>> value = sscanf(buffer(loc+22:end), '%f')
value =
-78.5771
If you had more work to accomplish on the pattern matching side, you could use REGEXP. Example
>> str2double(regexp(buffer, '(?<=SCF Done: E\(\w{6}\) =\s*)-?[\d\.]*(?=\s*A\.U\.)', 'match'))
ans =
-78.5771
this regexp pattern would match any occurrence of SCF.. where RB3LYP could be any 6 alpha-numerical characters code and where the number would be followed by A.U..
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!