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
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 个评论
Alexandr Troshchanovskii
2013-1-17
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
2013-1-17
编辑:Alexandr Troshchanovskii
2013-1-17
Jan
2013-1-18
Please accept this answer, if it solves your problem.
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!