getappdata works to load a variable that was never set?
Show older comments
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 Comments
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
on 1 Oct 2017
Accepted Answer
More Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!