Extracting a double from a text file

4 views (last 30 days)
Hi everone,
I want to extract the number that in front of Volt[M/Y] from alarge Text file. the structure of the file is described bellow. After reading the files in matlab, i want to look for the numbers in front of Volt [M/Y]. I succeded reading the files, and i also tried to solve the task with the matlab function regexp:
Data= regexp(A,'M/Y]\s*\w*$','tokens');
I have a dificulty to write the aproppriate expression to save the right number. Could you plase give any hints?
Thank you
2.420 -28.87 3.0710
2.430 -30.82 2.1945
Volt [M/Y] -12.258812
700 -30.39 1.9684
900 -29.60 2.1034
Volt [M/Y] 100.05

Accepted Answer

Mathieu NOE
Mathieu NOE on 28 May 2021
my 2 cents suggestion (as I still struggle with regexp !)
bs = split(fileread('data.txt'));
values = bs(find(strcmp(bs,'[M/Y]')>0) + 1);
Mathieu NOE
Mathieu NOE on 31 May 2021
My pleasure
still have to workout regexp !!

Sign in to comment.

More Answers (0)


Find more on Characters and Strings 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!