about write in file

2 vues (au cours des 30 derniers jours)
UTA
UTA le 3 Juin 2013
Hi everyone: I have a exist file named as 'data.txt', and I want to write data into the file in every loop; but the update data always overwrite on the previous, how can I avoid this problem and write data in file as the size of n*2; my code as follow: the size of matrix h is n*2;
for i = 1 : 10
fid = fopen('data.txt','w+');
fprintf(fid,'%d\n',h(i,:));
fclose(fid);
end
Thank you so much!

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Juin 2013
for i = 1 : 10
fid = fopen('data.txt','at');
fprintf(fid,'%d\n',h(i,:));
fclose(fid);
end

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 3 Juin 2013
fid = fopen('data.txt','w+');
for i = 1 : 10
fprintf(fid,'%d\n',h(i,:));
end
fclose(fid);

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by