How can I solve this error about nargout function?

6 views (last 30 days)
John Fernand Racelis
John Fernand Racelis on 18 May 2022

Answers (1)

Walter Roberson
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
-nargout 0
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.
  1 Comment
John Fernand Racelis
John Fernand Racelis on 18 May 2022
function varargout = HumanSkinDiseaseDetection2(varargin)
% HUMANSKINDISEASEDETECTION2 MATLAB code for HumanSkinDiseaseDetection2.fig
% HUMANSKINDISEASEDETECTION2, by itself, creates a new HUMANSKINDISEASEDETECTION2 or raises the existing
% singleton*.
% H = HUMANSKINDISEASEDETECTION2 returns the handle to a new HUMANSKINDISEASEDETECTION2 or the handle to
% the existing singleton*.
% HUMANSKINDISEASEDETECTION2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HUMANSKINDISEASEDETECTION2.M with the given input arguments.
% HUMANSKINDISEASEDETECTION2('Property','Value',...) creates a new HUMANSKINDISEASEDETECTION2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before HumanSkinDiseaseDetection2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to HumanSkinDiseaseDetection2_OpeningFcn via varargin.
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
% Edit the above text to modify the response to help HumanSkinDiseaseDetection2
% Last Modified by GUIDE v2.5 18-May-2022 12:15:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @HumanSkinDiseaseDetection2_OpeningFcn, ...
'gui_OutputFcn', @HumanSkinDiseaseDetection2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
if nargout
[varargout{0:nargout}] = gui_mainfcn(gui_State, varargin{:});
gui_mainfcn(gui_State, varargin{:});
Where can I put the -nargout 0 function here?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!