problem with pushbutton reference in GUI

1 view (last 30 days)
Hi all, first off, I've seen this question asked several times all over the internet but there doesnt seem to be a solid answer to it anywhere (at least not a workable one for my situation). I am creating a GUI that inputs data into a genetic algorithm. I created this GUI in GUIDE and to start the process I have made a run button that calls the main function. I want to set the run button to display a different string as well as disable it for the run of the main function. So far the callback for the button looks like this:
function run_button_Callback(hObject, eventdata, handles)
set(handles.run_button,'string','Running...','enable','off');
guidata(hObject,handles);
[X] = get_X(hObject,handles,eventdata);
Tower_driver(X)
% Reset button
set(handles.run_button,'string','RUN','enable','on')
When I run this GUI straight from the figure (that is, clicking on the .fig file and only running the GUI) I get this error:
Reference to non-existent field 'run_button'.
Error in TD_gui>run_button_Callback (line
687)
set(handles.run_button,'string','Running...','enable','off');
When I run the GUI from editor or in debugger mode to examine the handles struct, I don't get any error. Any reason why this would be happening? Thanks!
- Ryan

Accepted Answer

RyanJ
RyanJ on 24 May 2013
Edited: RyanJ on 24 May 2013
RESOLVED: after agonizing over this for the past few days I found the answer. For anyone with the same issue:
in the callback function, it is hObject, not handles.yourobject that holds the value stored in the object. Replace
set(handles.yourobject,'string',...)
with
set(hObject,'string',...)
This will resolve the issue

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!