Redirecting error and warning messages to a file when running a deployed MATLAB GUI

9 Ansichten (letzte 30 Tage)
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

Antworten (1)

Image Analyst
Image Analyst am 12 Jan. 2014
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()

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by