about write in file

1 次查看(过去 30 天)
UTA
UTA 2013-6-3
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!

采纳的回答

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

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by