why does GUIDE not save components handles

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 1월 17일

1 개 추천

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

What if I need to make .exe? sorry, but you suggestion sounds like not to use things if you don't know how .
Sean de Wolski
Sean de Wolski 2013년 1월 17일
If you need to make an executable, use the *.m file as the entry-point or main file. The *.fig file should packaged automatically based on the dependency analysis and then the *.m file will be run.
The *.fig file with a GUIDE GUI is literally just a figure with no intelligence. The *.m file gives it that intelligence which is why it needs to be run..
Alexandr Troshchanovskii
Alexandr Troshchanovskii 2013년 1월 17일
편집: Alexandr Troshchanovskii 2013년 1월 17일
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 2013년 1월 18일
Please accept this answer, if it solves your problem.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

태그

질문:

2013년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by