How to save results in a file without overwritting previous results????
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to open a file and save in it specific results of a simulation but without overwritting the previous ones tha I have saved.
댓글 수: 0
답변 (1개)
Chunru
2022년 4월 27일
Use append option when you save the data to files. [You can also use low-level fopen with option 'a+' for appending]
% create a file
a1 = [1 2 3];
save('test.txt', 'a1', '-ascii');
type test.txt
%% Now save more data with append
a2 = [4 5 6];
save('test.txt', 'a2', '-ascii', '-append');
type test.txt
댓글 수: 2
Walter Roberson
2022년 4월 28일
writetable() and writematrix() support append options these days.
save() to a .mat file supports '-append'
save() to text suports '-append'
For binary files, fopen() with 'a' always appends to the end of the file (even if you have used fseek() to reposition.). fopen() with 'a+' starts at the end of the file, but permits you to fseek() and write at whatever position you are at.
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!