Extracting data from an unformatted text file
2 次查看(过去 30 天)
显示 更早的评论
Hi, I want to extract certain values from an unformatted text file, in the example I use the regexp function entering the format of the data I want to extract.
(file format)
...
<<<<< Function evaluation summary (I1): 582 total (581 new, 1 duplicate)
<<<<< Best parameters =
31 x1
7 x2
87 x3
83 x4
3 x5
63 x6
5 x7
72 x8
12 x9
51 x10
67 x11
82 x12
81 x13
35 x14
52 x15
13 x16
32 x17
19 x18
73 x19
24 x20
50 x21
71 x22
61 x23
22 x24
23 x25
27 x26
58 x27
77 x28
1 x29
<<<<< Best objective function =
1.0119441809e+00
...
The output does not work because it extracts undesired values.
str = fileread('OUTPUT.out');
expression = '\d*\s\w\w' ;
regexp = regexp(str,expression, 'match');
How can I extract the values with the presented format?
2 个评论
Rik
2021-4-30
You should rename your file to txt and attach it. That way, we can taylor our code to your exact file format.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!