Error: ??? Input argument "handles" is undefined.
조회 수: 13 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2016년 12월 2일
편집: Walter Roberson
2016년 12월 2일
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
Walter Roberson
2016년 12월 2일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!