How to read floating point number 5.3246-5 as 5.3246E-5 in text file

1 view (last 30 days)
I want to read 9.4345-51.8998772.518305 in a text file as 9.4345E-5, 1.899877, 2.518305 by recognizing it as a different number by 8 characters. When I use the '%8f' option in sscanf, it reads as 9.4345, -51.8998, 772.5183.
Is there any way? Please.

Answers (1)

Stephen23
Stephen23 on 26 May 2022
str = '9.4345-51.8998772.518305';
tmp = cellstr(reshape(str,8,[]).');
tmp = regexprep(tmp,'(?<=\d)([-+]\d+)$','E$1')
tmp = 3×1 cell array
{'9.4345E-5'} {'1.899877' } {'2.518305' }
vec = str2double(tmp)
vec = 3×1
9.4345e-05 1.899877 2.518305

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!