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)
fid = fopen('disperse_error_log.txt', 'a');
fprintf(fid, 'Error at %s\n%s\n', datestr(now), getReport(ME, 'extended'));
- 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);
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'))