getappdata works to load a variable that was never set?
Mostrar comentarios más antiguos
Hi I've been using getappdata/setappdata to share variables across different callbacks in my GUI.
Basically what happens is that the user calls a one of the callbacks to load an image into the application and i used setappdata, so that the image can be called somewhere else.
the problem i discovered while debugging on the line of code : >> mask=getappdata(0,'mask');%recieve the mask
if i read this line even without having saved the variable "mask" (with setappdata) somehow the variable mask still gets loaded into the workspace.
does anyone know what causes this? how i can correct it? or if there is an alternative to sharing variables across callback
3 comentarios
Your title "getappdata works to load a variable that was never set?" is incorrect: the variable was set, the first time you ran that code. This is the problem here:
getappdata(0,...)
You are storing in the root graphics object (0), which is just as bad as using global variables: it produces untraceable bugs that are almost impossible to debug. Just like you are finding out now.
Betzalel Fialkoff
el 1 de Oct. de 2017
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!