Regexp to match floating numbers and ignore scientific notation numbers

3 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 14 Aug 2022
Edited: Stephen23 on 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

Sign in to comment.

Answers (1)

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

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by