GUI Handles Visibility Different
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

Please see the attached image. I'm using the handles structure to pass values between a GUI and a main m file, but the variables I've created disappear when I try to access them in the main file, while I am able to access the other handles with the different icon. I'm not sure why I'm unable to access the last two variables.
0 commentaires
Réponses (1)
Walter Roberson
le 22 Avr 2017
After you change the contents of the handles structure, be sure to use
guidata(hObject, handles)
where hObject is the name of the first parameter to your function (GUIDE tends to name it hObject)
2 commentaires
Walter Roberson
le 22 Avr 2017
If you are running a routine, and a different routine updates handles, then that does not update the handles in the first routine.
For example, you might have a pushbutton that starts a plotting loop
function do_plotting(hObject, event, handles)
while handles.keep_going
do some plotting
drawnow()
end
and you might have a pushbutton
function stop_plotting(hObject, event, handles)
handles.keep_going = false;
guidata(hObject, handles);
that is intended to tell the loop to stop.
But "handles" is not a global structure. What gets passed in to a routine is a copy of the handles structure as of the time the routine starts. The guidata() in stop_plotting updates the master copy of the handles structure but does not affect the copy that is local to the do_plotting function.
If you are running a routine and you have reason to expect that some other routine might have updated handles and you need to see the updated version, then you need to use guidata() to retrieve the updated copy:
function do_plotting(hObject, event, handles)
while true
handles = guidata(hObject); %pull in current version
if ~handles.keep_going; break; end
do some plotting
drawnow()
end
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!