Searching for values that a particular variable takes in a single text file
1 view (last 30 days)
Show older comments
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
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.
Accepted Answer
Azzi Abdelmalek
on 13 Aug 2013
If your text file contains only numbers, you can use
M=dlmread('YourFilename.txt')
3 Comments
Azzi Abdelmalek
on 13 Aug 2013
You can use fgetl to read your file then parse the result with regexp
More Answers (1)
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
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.
See Also
Categories
Find more on Text Files 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!