How to write to a fopen text file in a new row without deleting previous text?

조회 수: 6 (최근 30일)
Shel
Shel 2018년 12월 3일
답변: Jan 2018년 12월 3일
I have doing a series of computation by matlab and for that I have 400 files (to do the proces on) and I am going to write a loop to do the same process several times ... I want the new results to be written in the same file but in a new row, can you please help me how I can do so?
Thanks,
Attachement:he result of my file for the first number of loop. .. I want the new results (500 number of calculation) to be printed in new 500 columns beside these dta.
now I use this command:
H='result.txt';
file1=fopen(H,'w');
%the commands
fprintf(file1,'%1.0f %5s %6.1f %15s %6.1f %15s %6.0f %15s %-6.0f %15s %6.3f \r\n',i, '', area,'',mean,'',mmax,'',mmin, '', proportion);
data.png
  댓글 수: 3
Shel
Shel 2018년 12월 3일
actually, I have not used dlmwrite before, how can I use it?
I mean as I read the reference page, it should be like dlmwrite(filename, M, '-append') and M should be a predefined data, matrix ...
but in my case I should calculated each data of a row seperately for a series of my data (that is image) ... so is it possible to write each value calculated for an image like what I have done with fprintf during the calculation?
can you guide me more on this please?
madhan ravi
madhan ravi 2018년 12월 3일
you can calculate the values totally and store it as a matrix and then write it to a file but if you insist ...
yes you can do it for instance
inside loop
m = .... % contains some elements % here you don't have to save m in each iteration because you write it in the file
dlmwrite('sample.txt',m,'Delimiter', ' ' , '-append')

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 12월 3일
What about:
file1=fopen(H, 'a'); % Instead of 'w'

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by