Regexp to match floating numbers and ignore scientific notation numbers

4 Ansichten (letzte 30 Tage)
I hava a script to extract one value from each line of a text file.
All the lines are in this sort:
5603 1 1 1 1 115 1 17 1 1 1.00212E-17 0.00528
I need to extract only the last value, which in this line is: 0.00528.
How can I organize the Regexp expression to only pull these type of values?
Thanks!
  3 Kommentare
Thamer Albagami
Thamer Albagami am 14 Aug. 2022
The file is too large and doesn't have the same format of lines. The data are organzied in unstrcutued format, like:
Data1 = [
1 1 1 1 1 1 1 1 1 1 8.02709E-20 0.05846
. . . . . . . . . . . .
. . . . . . . . . . . .
] ;
HData1X = [
-1.07100E+01 1.07100E+01 0.00000E+00
];
HData1Y = [
-1.07100E+01 1.07100E+01 0.00000E+00
];
So, I managed to pull the lines I need and ignore the others. I only need the correct format of Regexp to pull the value of interest, which is a float with 5 significant difits from the lines that are like:
1 1 1 1 1 1 1 1 1 1 8.02709E-20 0.05846
thanks!
Stephen23
Stephen23 am 14 Aug. 2022
Bearbeitet: Stephen23 am 14 Aug. 2022
If you have already isolated that line and the value you want is always the last one, then a simple and efficient approach would be to SCCANF the entire line and use indexing to obtain the last value:
str = '603 1 1 1 1 115 1 17 1 1 1.00212E-17 0.00528';
vec = sscanf(str,'%f');
num = vec(end)
num = 0.0053

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 14 Aug. 2022
\d+\.\d{5}\>

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by