Error: ??? Input argument "handles" is undefined.

13 visualizaciones (últimos 30 días)
Aquiles
Aquiles el 2 de Dic. de 2016
Comentada: Walter Roberson el 2 de Dic. de 2016
Good day,
I was tinkering with a GUI in GUIDE and after adding some code that performs some GUI operations (enabling/disabling buttons, running some calculations, updating fields and values) I got the following error in command line:
Input argument "handles" is undefined.
Error in ==> design_calculator>disable_graphs at 633 set(handles.toggle_currentwaveform,'Enable','off');
Error in ==> design_calculator>design_calculator_OpeningFcn at 103 disable_graphs;
Error in ==> gui_mainfcn at 221 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> design_calculator at 42 gui_mainfcn(gui_State, va*rargin{:});
I am unsure why this error occurs, but it widespread in all the functions that use the handles structure. The specific code for the above error is as follows:
function disable_graphs(handles)
set(handles.toggle_currentwaveform,'Enable','off');
set(handles.toggle_voltagewaveform,'Enable','off');
guidata(hObject, handles);
Any ideas? This error occurs in every function, so I presume that there is some higher order shenanigans going on. Any help is appreciated!
  1 comentario
Mischa Kim
Mischa Kim el 2 de Dic. de 2016
Attach the entire code (.fig and .m) so we can help.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 2 de Dic. de 2016
Editada: Walter Roberson el 2 de Dic. de 2016
Your code invokes
disable_graphs;
at line 103, but you have defined
function disable_graphs(handles)
So you are not passing anything to the function but your function expects something to be passed.
Caution for future reference: all _CreateFcn callbacks are invoked with handles being empty. The handles structure will not be populated until all _CreateFcn have finished. handles will be populated by the time the _OpeningFcn is executed.
  2 comentarios
Aquiles
Aquiles el 2 de Dic. de 2016
Hi Walter,
Yes that is correct. I presumed I was using the correct syntax but I was wrong. Can you please elaborate on how to properly use the handles structure in user-defined functions? I've pored through the documentation looking for the right syntax but cannot find anything.
Walter Roberson
Walter Roberson el 2 de Dic. de 2016
handles is never passed automatically to any function.
Callback functions are always automatically passed the source object (sometimes called src, sometimes called hObject) and an event structure (that might be empty.) They are not automatically passed handles
However, if you use GUIDE and create a graphics object and go through GUIDE to create the callback for it, then GUIDE programs the appropriate callback property to some code that fetches the current handles object and then calls the user-provided function, passing in the two automatic arguments and also passing in handles. If you look closely with the properties inspector, the appropriate callback property can be seen the way that GUIDE actually fills it in. What GUIDE does automatically is not visible in the source code: it is what GUIDE sets as properties of the graphics objects, and the properties are saved when you ask GUIDE to save the configuration.
You are using GUIDE, but you are wanting to call your own routine that is not part of the GUIDE callback structure: you are putting the call directly into the code. In that situation, nothing will be passed automatically, and you need to provide it with all parameters it needs to work.
Inside the design_calculator_OpeningFcn routine, you can safely do that by just coding
disable_graphs(handles);
and so "manually" pass handles in to your routine.
But for future reference: if you happen to get down into CreateFcn routines, then be aware that handles is empty or not provided for calls to the CreateFcn routines. You are not trying to code anything into a CreateFcn routine at this time, so this is not information you need to know right now, but it is something to keep in mind for the future.

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by