Regexp to match floating numbers and ignore scientific notation numbers
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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)
Antworten (1)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!