why does GUIDE not save components handles

1 view (last 30 days)
M-file code:
function pushbutton1_Callback(hObject, eventdata, handles)
handles.myValue=999;
disp(5);
disp(handles);
If start this code from M-file by F5 button, the command windows shows:
5
figure1: 173.0032
pushbutton1: 179.0032
axes1: 174.0032
output: 173.0032
myValue: 999
But if start by double clicking the .fig file, command window shows only:
5
myValue: 999
In Matlab HELP it is said: "When the GUI is fully initialized, the handles structure contains only handles to all the components in the GUI and custom data added in any CreatedFcn callbacks and/or the OpeningFcn."
but at the same time I see error messages about missing fields in the handles structure while my gui program is running.
For example this code:
function pushbutton1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
plot(rand(5));
will work well ONLY if start it from M-file with F5 button, or if create the handles.axes1 MANUALY like this:
function axes1_CreateFcn(hObject, eventdata, handles)
handles.axes1=hObject;
guidata(hObject, handles);
Otherwise Matlab displays an error: "Referring to non existing field handles.axes1"
I was sure that the GUI handle structure would consist handles to all added in GUIDE components as it is said in HELP. In result, relying on this, I waste so much time finding reason for that "non existing filelds" messages. May be

Answers (1)

Sean de Wolski
Sean de Wolski on 17 Jan 2013
This is why you never run a GUIDE GUI from the figure.
Always run the *.m file associated with it. This creates all of that stuff and does the initializations.
  4 Comments
Alexandr Troshchanovskii
Alexandr Troshchanovskii on 17 Jan 2013
Edited: Alexandr Troshchanovskii on 17 Jan 2013
Thank you very much Sean! You really helped me to understand the things.
.. now I understood that all the initialization data is in the *.m file that's why I must start it first.
Jan
Jan on 18 Jan 2013
Please accept this answer, if it solves your problem.

Sign in to comment.

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!