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

22 views (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 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()

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!