matlab - dlmwrite appends to the end -
matlab - dlmwrite appends to the end -
i writing several lines text file, among matrix. decided utilize fprintf normal text messages , utilize dlmwrite writing matrix file. however, action done in while loop. here outline:
k=0; while (k<10): fprintf(file,'%s', 'hello'); dlmwrite(file,m ,'-append', 'newline', 'pc'); fprintf(file, '%s' , 'goodbye'); k= k+1;
however, when open file, matrices appended end of text file instead of each beingness between hello , goodbye. there way prepare issue?
it may have -append
option, according help appends result end of file.
you accessing same file 2 functions, fprintf
, dlmwrite
.
this not efficient, closing file after every write fprintf
work:
clear close file_name = 'aa.txt'; file = fopen(file_name, 'w'); fclose(file); file = fopen(file_name, 'a'); m = randn(5); kk = 1:10 file = fopen(file_name, 'a'); fprintf(file, 'hi\n'); fclose(file); dlmwrite(file_name, m ,'-append', 'newline', 'pc'); file = fopen(file_name, 'a'); fprintf(file, 'bye\n'); end
if not, seek print matrix other funcion create , uses same file handler fprintf
.
matlab
Comments
Post a Comment