Changing a specific column in txt file

2 ビュー (過去 30 日間)
Varghese
Varghese 2014 年 1 月 15 日
回答済み: Walter Roberson 2014 年 1 月 15 日
Dear group, I am looking to change the value in a specific column in a txt file. In the attached txt file, I want to change the 1's in the third column to the previous value (same column, previous row) and delete the previous row. Any help would be much appreciated.

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 1 月 15 日
There is no mechanism to change text files "in place" -- not unless the replacement is exactly the same size as the original.
You need to read the file and write each line in turn to a new file, except writing the new versions of the lines instead of writing the old versions. Then once past the part to change, keep reading from the old and copying to the new. Close the files. If needed, rename the new file to have the name of the old file.

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by