MATLAB: Problem with pushbutton reference in GUI

callbackerrorguiguidehandlesnon-existent fieldset

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

Best Answer

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