How to print outputs in different lines and save them in a file?
조회 수: 8 (최근 30일)
이전 댓글 표시
Franck paulin Ludovig pehn Mayo
2022년 2월 17일
댓글: Franck paulin Ludovig pehn Mayo
2022년 2월 18일
I have two different pushbottons that print some outputs out whenever i click on them. I would like to save those outputs in the same file. The issue i am having is that , everytime i click on one the previous output is deleted.All this is done in guide.
For example. i am expecting sth like
I FEEL IT
I DON'T FEEL IT
I DON'T FEEL IT
...
%This is the first pushbotton
fileID = fopen('exp.txt2','w');
YES = "I FEEL IT";
fprintf(fileID,"%s\n",YES);
fclose(fileID);
%This is the second pushbutton
fileID = fopen('exp.txt2','w');
YES = "I FEEL IT";
fprintf(fileID,"%s\n",YES);
fclose(fileID);
댓글 수: 0
채택된 답변
Voss
2022년 2월 17일
Use 'a' rather than 'w' in fopen():
fileID = fopen('exp.txt2','a');
to open a file for appending, without discarding the existing contents.
댓글 수: 7
Voss
2022년 2월 18일
My suggestion was not to change the callback functions of the buttons - those can still do fopen(__,'a').
Rather, at the start of the program, i.e., in the OpeningFcn, that's where you should fopen(__,'w') your file to make sure it exists and is empty.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!