フィルターのクリア

GUI stops working after pushbutton function has completed

3 ビュー (過去 30 日間)
Oscar Knights
Oscar Knights 2016 年 4 月 20 日
コメント済み: Oscar Knights 2016 年 4 月 22 日
I have created a GUI (called GNgui) using GUIDE that runs a function when a 'Scan' button is pressed. It disables all the other buttons/fields in the GUI until it stops running, where it enables all the buttons again.
After the function runs (successfully), I'd like to be able to hit the 'Scan' button again to repeat the process, but every time I do, I get the following error message:
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('fileName_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
This isn't mutually exclusive to that push button either. When I try to press any other button (or even try to close the GUI window), I get a very similar error.
Any ideas? I've attached my .m file.
PS: I realise the code is a little messy, I'm trying to update and improve on some code someone else wrote.
  2 件のコメント
Image Analyst
Image Analyst 2016 年 4 月 20 日
We'd need the .fig file also.
Oscar Knights
Oscar Knights 2016 年 4 月 20 日
Apologies... I've attached the .fig file.

サインインしてコメントする。

回答 (1 件)

Meade
Meade 2016 年 4 月 20 日
I believe that the call back is written incorrectly. Your anonymous function syntax is telling the callback function that the second input is "evt" which is a struct by default. However, you're passing "hObj" as the second input.
try this:
@(hObject,eventdata)GNgui(hObject,eventdata,guidata(hObject))
  7 件のコメント
Meade
Meade 2016 年 4 月 21 日
Ok, so the problem seems to be that the 'handles' argument that is being passed to ALL your callbacks is empty.
I can't run the full gui since it's looking for some sort of COM connection, but you need to get all the handles for all the things you created in the GUIDE creator.
As a start, swap lines 41:45 with these
hFig = ancestor(hObject,'figure');
handles = guihandles(hFig);
% Choose default command line output for GNgui
handles.output = hObject;
% Update handles structure
guidata(hFig, handles);
This adds the structure 'handles' as guidata to the figure. Then, whenever a callback has the 'handles' arument, it should get this list of items.
Oscar Knights
Oscar Knights 2016 年 4 月 22 日
I updated lines 41:45 with the code you provided but I still receive the following error:
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('fileName_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Undefined function 'GNgui' for input arguments of type 'struct'.
Error in
@(hObject,eventdata)GNgui('scanButton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
When you say I need to 'get all the handles', what should I do with them? Again, sorry about being a bit of a novice when it comes to these things.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by