Store value from text file

1 view (last 30 days)
Jorre De Backer
Jorre De Backer on 29 Apr 2020
Commented: Jorre De Backer on 5 May 2021
So I have a text file and i need to store the sampling rate value like this:
samplingRate1 = 1000;
samplingRate2 = 2000;
I don't know how to find and store these values. The next thing is that the text file is very long but I only have to read the second line.
I tried using textscan but I am doing something wrong i think.
Any suggestions.
text file:
#kjkjj,lzddz;mzdm;dzm;mdz
# { {"sensor": ["CUSTOMV"], "device name": "00:07:80", "sampling rate": 1000, "position": 1, "sampling rate":2000, }}
#zffzfzvzgrgr
5502 0 0 11351 6478 7654 1936
3740 0 6594 6830 8041 5507 1 0 11281 6520 7608 1956
3741 0 6564 6797 8022 5608 2 0 11347 6446 7624 1909
3742 0 6543 6791 8046 5528 3 0 11272 6448 7591 1896
3743 0 6554 6776 8034 5570 4 0 11254 6395 7587 1948
3744 0 6544 6771 8028 5530 5 0 11259 6411 7602 1881
3745 0 6595 6752 8053 5587 6 0 11271 6408 7641 1944
........(keeps going)

Accepted Answer

Jalaj Gambhir
Jalaj Gambhir on 19 May 2020
Hi,
To read the sampling rates mentioned in the text file 'regexp' is your best bet.
You can do so by:
s = fileread('test.txt'); % your text file's name
W = regexp(s,'"sampling rate":\s*([0-9]*)','tokens');
result = [W{:}].'
Also, to read a particular line number from a text file, you can refer to the solution provided here.
Hope this helps!

More Answers (0)

Categories

Find more on Data Import and Export 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!