Use diary off with Closerequestfcn
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello everybody,
I am trying to incorporate the diary off command within the Close RequestFcn expression, but I always get an error, here the details:
The idea: I open a figure and then start to record the command window. Then, if I manually close the figure by pressing on the x at the top right corner of the figure window, the command window displays a text and, at the same time, the diary stops recording.
Here is the code that does not work:
fig = figure();
diary write.txt;
fig.CloseRequestFcn = @(~,~){fprintf('Script aborted\n'); close(fig, 'force'); diary('off')};
Here is the error:
Error using diary
Too many output arguments.
Error in Temp4>@(~,~){fprintf('Script aborted\n');close(fig,'force');diary('off')} (line 5)
fig.CloseRequestFcn = @(~,~){fprintf('Script aborted\n'); close(fig, 'force'); diary('off')};
Error while evaluating DestroyedObject CloseRequestFcn.
Note: if I remove "diary off" from the expression it works fine, but then I cannot delete write.txt file until I manually type "diary off" in the command window.
I hope I managed to explain myself. Really thank you in advance to everyone for the help!
댓글 수: 0
답변 (1개)
Abhinav Aravindan
2024년 12월 11일
A similar issue to yours has been addressed in the following link:
To resolve the issue, you may instead define a seperate function to implement the required operations as follows:
fig = figure();
diary('write.txt');
fig.CloseRequestFcn = @(src, event) closeFigureFcn(src);
function closeFigureFcn(fig)
fprintf('Script aborted\n');
diary('off');
delete(fig);
end
Please refer to the below documentation for further detail:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!