When a script or function outputs too many arguments, it means that either the function is not defined to return that many values or that the function is called with too many output variables. In either case, the error can be handled in the following ways:
nargout
function to check the number of output variables expected by the function:main.m118 chars5 lines
In the above example, if the number of output variables expected is greater than 3, the error will be thrown.
try-catch
block to handle such errors:main.m147 chars6 lines
In the above example, if myFunction
outputs 4 variables instead of 3, then the error will be caught and displayed.
By using these methods, you can handle the "too many output arguments" error in MATLAB.
gistlibby LogSnag