Searching for values that a particular variable takes in a single text file

1 view (last 30 days)
Hello,
I need to work on the values that a particular variable takes up at different times in a particular text file. I need these values so that I can compare them with a certain threshold level that I will set in the program. I am a new to MATLAB. Please help.
Thank you.
  4 Comments
Cedric
Cedric on 13 Aug 2013
Please post a copy/past of part of the file (e.g. 10-20 lines) so we can see the format.
Abhishek
Abhishek on 13 Aug 2013
Edited: Azzi Abdelmalek on 13 Aug 2013
This is how the text file looks. I need to check if the AvgValue is greater than or lesser than a particular threshold everytime, the counter encounters the AvgValue.
44 20 4 516
45 20 4 515
43 21 4 554
42 22 4 578
43 22 4 540
41 23 4 576
41 24 4 426
41 25 4 300
47 25 4 302
41 26 4 285
45 26 4 177
46 26 4 136
47 26 4 337
48 26 4 343
41 27 4 349
47 27 4 380
48 27 4 533
49 27 4 92
41 28 4 374
42 28 4 178
43 28 4 156
44 28 4 154
46 28 4 315
47 28 4 478
48 28 4 558
40 29 4 444
44 29 4 266
45 29 4 452
46 29 4 496
AvgValue: 378.000000
ROI: 2
NrOfVoxels: 34
45 37 5 395
46 37 5 331
44 38 5 506
45 38 5 480
46 38 5 412
42 39 5 529
43 39 5 566
45 39 5 554
46 39 5 495
40 40 5 557
43 40 5 587
44 40 5 564
46 40 5 463
47 40 5 416
48 40 5 221
40 41 5 574
46 41 5 452
47 41 5 431
48 41 5 128
43 42 5 525
45 42 5 439
46 42 5 374
42 43 5 532
43 43 5 485
44 43 5 478
45 43 5 367
46 43 5 406
47 43 5 295
43 44 5 503
44 44 5 522
45 44 5 507
46 44 5 564
45 45 5 606
45 46 5 687
AvgValue: 469.000000

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Aug 2013
If your text file contains only numbers, you can use
M=dlmread('YourFilename.txt')
  3 Comments

Sign in to comment.

More Answers (1)

Cedric
Cedric on 13 Aug 2013
I would go for something like:
buffer = fileread('data.txt') ;
match = regexp(buffer, '(?<=AvgValue:\s*)[\d\.]+', 'match') ;
avgValue = str2double(match) ;
and then analyze avgValue which is a numeric array.
  5 Comments
Cedric
Cedric on 15 Aug 2013
If it is really 688kB (and not MB), could you email me the file please so I can perform some tests? This is a small file actually, so its processing shouldn't take more than a few seconds.
Cedric
Cedric on 16 Aug 2013
Edited: Cedric on 16 Aug 2013
Ok, the positive look-behind takes time. Please, try the following:
buffer = fileread('feedback0005_plots_Aphasia.ert') ;
tokens = regexp(buffer, 'AvgValue:\s*([\d\.]+)', 'tokens') ;
avgValue = str2double([tokens{:}]) ;

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!