How can I solve this error about nargout function?
5 views (last 30 days)
Walter Roberson on 18 May 2022
(That looks like GUIDE code)
You are trying to do code generation with variable numbers of output. MATLAB Coder is not able to analyze the code in enough detail to create proofs of the maximum number of outputs that will ever be needed.
Although the comments suggest that the only output possible is the handle to the gui, that is not accurate. You might have altered the openfcn callback to uiwait() for a close request. In such a case the outputs of the function would depend on what you stored in the outputs property of the handle -- potentially variable length depending on user actions and on input arguments. So Coder is not going to be able to prove maximum outputs in most cases... too complicated.
Is it at all plausible that you might have put in a uiwait like I gave as a hypothesis above? Yes!! Remember that GUIs are figures and that figures are destroyed when programs return. You might have another layer of code that is calling your gui and storing the handle returned and uiwait at that hypothetical outside level. It could happen. But far more likely is that you are asking to directly compile the GUI itself... and if so then unless you remembered to put in the uiwait then returning from the openfcn would be a request to terminate the program and the GUI would disappear immediately after initialization! Thus the fact that you are using MATLAB Coder makes it likely that the outputfcn mechanism of variable outputs will be invoked (at least nominally)
If you are indeed compiling your GUI as the main entry point, then you are unlikely to have any meaningful outputs: if your code bothers to construct outputs then there unlikely to any layer to receive the outputs.
So what you should typically do edit the function to not have any outputs, and edit the output fcn to not try to set varargout, and edit openfcn to uiwait(). Solve the problem by not having outputs that cannot be used.
But what you can do instead is invoke Coder with
in the flags. I am not sure at the moment where you could insert the flags if you are using the gui interface to compile.