Borrar filtros
Borrar filtros

Write a substring in a Text file with existing string

2 visualizaciones (últimos 30 días)
Saeed Soltani
Saeed Soltani el 30 de Mayo de 2016
Editada: Saeed Soltani el 2 de Jun. de 2016
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?

Respuesta aceptada

Stephen23
Stephen23 el 30 de Mayo de 2016
Editada: Stephen23 el 30 de Mayo de 2016
Change the fopen file permission from 'w' (write) to 'a' (append):
fid = fopen('File.text','at');
  7 comentarios
Stephen23
Stephen23 el 31 de Mayo de 2016
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 el 2 de Jun. de 2016
Editada: Saeed Soltani el 2 de Jun. de 2016
I got a solution here

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by