How to get error line in a compiled code?

7 ビュー (過去 30 日間)
grega
grega 2019 年 1 月 27 日
回答済み: Riya 2025 年 4 月 25 日
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?

回答 (1 件)

Riya
Riya 2025 年 4 月 25 日
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'))

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by