Redirecting error and warning messages to a file when running a deployed MATLAB GUI
조회 수: 14 (최근 30일)
이전 댓글 표시
I am developing a MATLAB GUI that is transitioning from alpha to beta. I would like to be able to receive debug logs from the users. I use disp, error and warning at different places in the code. Is it possible to deploy the GUI such that the messages destined to MATLAB's command window are redirected to stdout or file (say debug.txt)?
Thanks,
Shalin
댓글 수: 0
답변 (1개)
Image Analyst
2014년 1월 12일
See if the "diary" command is what you're looking for.
You can also write just errors to a log file if you catch them and call a function, like WarnUser() in the code below, that will alert the user and append the message to a log file.
try
% Your code goes here.
catch ME
% You get here if there was an error in this function
% or some function this function called that was unhandled.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
WarnUser(errorMessage);
end
====================================================================
function WarnUser(errorMessage)
% Alert user via the command window and a popup message.
fprint(1, '%s\n', errorMessage); % To command window.
uiwait(warndlg(errorMessage));
% Open the Error Log file for appending.
fullFileName = 'Error Log.txt';
fid = fopen(fullFileName, 'at');
fprint(fid, '%s\n', errorMessage); % To file
fclose(fid);
return; % from WarnUser()
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!