about write in file

조회 수: 2 (최근 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에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by