MATLAB: Write a substring in a Text file with existing string

text filetextscanwrite

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?

Best Answer

Change the fopen file permission from 'w' (write) to 'a' (append):
fid = fopen('File.text','at');