Store value from text file

3 次查看(过去 30 天)
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)

采纳的回答

Jalaj Gambhir
Jalaj Gambhir 2020-5-19
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by