Extract numeric fields from a long log file
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi.
I have a long log file made of many blocks like the following one
Time = 19.419
Courant Number mean: 0.112358 max: 0.729364
DILUPBiCG: Solving for Ux, Initial residual = 0.00202902, Final residual = 7.96821e-06, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 0.0078399, Final residual = 1.04306e-06, No Iterations 2
DILUPBiCG: Solving for Uz, Initial residual = 0.00704655, Final residual = 7.59091e-07, No Iterations 2
GAMG: Solving for p, Initial residual = 0.0245913, Final residual = 0.000711161, No Iterations 2
GAMG: Solving for p, Initial residual = 0.000859937, Final residual = 3.0172e-05, No Iterations 5
time step continuity errors : sum local = 1.62666e-09, global = -2.99489e-13, cumulative = 4.702e-09
GAMG: Solving for p, Initial residual = 0.00108059, Final residual = 4.57517e-05, No Iterations 2
GAMG: Solving for p, Initial residual = 5.2982e-05, Final residual = 7.80645e-07, No Iterations 9
time step continuity errors : sum local = 4.21046e-11, global = -3.72853e-15, cumulative = 4.702e-09
ExecutionTime = 52871.2 s ClockTime = 68177 s
I would like to extract some of these numbers. I tried with textscan but I don't know how to specify the format correctly.
Thank you very much for the help. Luca
0 Kommentare
Antworten (1)
Walter Roberson
am 26 Sep. 2013
LogText = regexp( fileread('YourLogFile.txt');, '\n', 'split');
NumericFields = regexp(LogText, '-?\d[^-+.e0-9]*', 'match');
NumericFields will then be a cell array with one entry per line of the original file (and possibly one extra entry at end of file). Each cell array entry will then be a cell array of strings, one numeric string per entry. So NumericFields{K} will be a cell array of strings, one string per numeric entry on the line.
Note that this has not been made selective about which lines are converted (as you did not give any indication as to which you wanted), so there will be some NumericFields{K} with one entry (e.g., Time line}, some with two (e.g., ExecutionTime line), a number with three per line with the source varieties not distinguished...
0 Kommentare
Siehe auch
Kategorien
Mehr zu Large Files and Big Data 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!