How to write a calculated number into a text file…!

1 回表示 (過去 30 日間)
Loran
Loran 2014 年 9 月 14 日
コメント済み: Image Analyst 2014 年 9 月 14 日
Hello,
I have a big text file, which I want first to find a specific “TIME” line in the text file and then add a calculated variable (which I have done it before) underneath that TIME?
For example: add calculated variable “b” after TIME 380.
…..
TIME 350
TIME 360
TIME 370
TIME 380
b
TIME 390
TIME 400
TIME 410
TIME 420
TIME 430
TIME 440
Thanks so much!
Loran

回答 (1 件)

Image Analyst
Image Analyst 2014 年 9 月 14 日
Try fgetl() followed by strfind() to find the desired "TIME" line. Then, once you've found it call fgetl() to read the "b" line and use str2double to convert that string into a numerical variable that you can use to add be to whatever you want to add it to.
  2 件のコメント
Loran
Loran 2014 年 9 月 14 日
Thanks so much.
I am new to Matlab with very little experience! I tried but did not work. I am sure I did something wrong. I would appreciate if you can elaborate it more!
thanks.
Image Analyst
Image Analyst 2014 年 9 月 14 日
You forgot to attach your code, and most importantly, the text file. Also let me know what time number and "b" that immediately follows it you want to extract - I don't know if there is just one b in there or if there are tons of b's in there and you just want one particular one.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by