Write a substring in a Text file with existing string

조회 수: 1 (최근 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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by