フィルターのクリア

Write a substring in a Text file with existing string

2 ビュー (過去 30 日間)
Saeed Soltani
Saeed Soltani 2016 年 5 月 30 日
編集済み: Saeed Soltani 2016 年 6 月 2 日
Hi, I would like to write a word in the following of an existing string in text file, but with my code it deletes the whole and write the new word.
fid = fopen('File.text','w');
fprintf(fid,'%s', NewWord);
I just need to find end of line, and add the new word with only one space to the rest. Should I use textscan or?

採用された回答

Stephen23
Stephen23 2016 年 5 月 30 日
編集済み: Stephen23 2016 年 5 月 30 日
Change the fopen file permission from 'w' (write) to 'a' (append):
fid = fopen('File.text','at');
  7 件のコメント
Stephen23
Stephen23 2016 年 5 月 31 日
MATLAB reads fucntion files once and then stores them in memory. This makes them faster (and I guess some JIT optimization occur too). What you are trying to do is to dynamically change MATLAB code, which is not a recommended way of using MATLAB, because it is slow and buggy.
Saeed Soltani
Saeed Soltani 2016 年 6 月 2 日
編集済み: Saeed Soltani 2016 年 6 月 2 日
I got a solution here

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by