How to get error line in a compiled code?

3 visualizaciones (últimos 30 días)
grega
grega el 27 de En. de 2019
Respondida: Riya el 25 de Abr. de 2025
I run a compiled code and after some time get the following error which I am able to capture via diary function storing a commend line results on every execution in a txt file:
Error while evaluating TimerFcn for timer 'timer-1'
Output argument "varargout{5}" (and maybe others) not assigned during call to "disperse".
Since the "disperse" function is called 18 times per code execution, I cannot locate at which line in the compiled code the error occures. How to get the exact error line in the compiled code?

Respuestas (1)

Riya
Riya el 25 de Abr. de 2025
Hi,
The error you are facing usually occurs when a function is supposed to return multiple outputs, but not all of them are assigned during execution.
Since the “disperse” function runs 18 times, it is important to identify which function call is failing.
You can follow these debugging methods for the same -
  • Method 1: Wrap your “disperse” function code logic in a “try-catch” block to log errors without crashing. Then, log errors with MATLAB’s getReport” function to some log file.
function [varargout] = disperse(varargin)
try
% your function logic here
catch ME
fid = fopen('disperse_error_log.txt', 'a');
fprintf(fid, 'Error at %s\n%s\n', datestr(now), getReport(ME, 'extended'));
fclose(fid);
rethrow(ME);
end
end
  • Method 2: Log each function call to “disperse” function along with the timestamp and input count to a file to trace which call fails.
fid = fopen('disperse_log.txt', 'a');
fprintf(fid, 'Called at %s with %d inputs\n', datestr(now), nargin);
fclose(fid);
These above-mentioned steps will help pinpoint the exact function call and the input which is causing the issue.
For more details, kindly refer to the following official documentation:
web(fullfile(docroot, ‘simulink/slref/simulink.matlabfunctionconfiguration.getreport.html'))

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by