필터 지우기
필터 지우기

Store value from text file

조회 수: 2 (최근 30일)
Jorre De Backer
Jorre De Backer 2020년 4월 29일
댓글: Jorre De Backer 2021년 5월 5일
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!
  댓글 수: 1
Jorre De Backer
Jorre De Backer 2021년 5월 5일
thank you for the helpful answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by