why does GUIDE not save components handles
Mostrar comentarios más antiguos
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
Respuestas (1)
Sean de Wolski
el 17 de En. de 2013
1 voto
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 comentarios
Alexandr Troshchanovskii
el 17 de En. de 2013
Sean de Wolski
el 17 de En. de 2013
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
el 17 de En. de 2013
Editada: Alexandr Troshchanovskii
el 17 de En. de 2013
Jan
el 18 de En. de 2013
Please accept this answer, if it solves your problem.
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!