How can I replace a value that comes after a specific string in a text file?
2 ビュー (過去 30 日間)
古いコメントを表示
Ruchelly Almeida
2020 年 8 月 17 日
コメント済み: Ruchelly Almeida
2020 年 8 月 17 日
I need to read a text file, find a specific string and change the value/values after that string.
For example, I want to change the grade of a specific student in a text file with the following format:
Adrian 7.8
Brian 8.8
Caroline 9
David 8.7
Jessica 9.5
What would be the best way to accomplish that? I am able to find the name, but I can't replace the grade.
Thank you!
0 件のコメント
採用された回答
Antonio Ciociola
2020 年 8 月 17 日
編集済み: Antonio Ciociola
2020 年 8 月 17 日
Use textscan:
filename = 'nameofyourfile.txt';
fid = fopen(filename,'r');
[A] = textscan(fid,'%s %f')
Then you can rewrite your file (with new values) using "fprintf" :fprintf Help
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!