Store value from text file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jorre De Backer
le 29 Avr 2020
Commenté : Jorre De Backer
le 5 Mai 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)
0 commentaires
Réponse acceptée
Jalaj Gambhir
le 19 Mai 2020
Hi,
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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!