Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to change the content of file?

1 visualización (últimos 30 días)
Ivan Mich
Ivan Mich el 21 de Mayo de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hello,
I I would like to change the content of a .txt file via a for loop, if it is possible.
I would like thw first value to be 10 and the last 250, and I want the content to be changed per 10 (I mean for k=10:10:250).
I am importing the .txt file.
How could I do that?
  7 comentarios
Walter Roberson
Walter Roberson el 22 de Mayo de 2020
save -ascii puts in a line of comments
Bjorn Gustavsson
Bjorn Gustavsson el 22 de Mayo de 2020
@Walter: What version of matlab started with that?

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Mayo de 2020
filename = 'Document2.txt';
while true
Val = load(filename) + 10;
if Val > 250; break; end
fid = fopen(filename, 'wt') ;
fprintf(fid, '%g\n', Val) ;
fclose(fid) ;
end
Not the way that I would implement myself, but for some reason it is important to you to work this way.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by