getappdata works to load a variable that was never set?
古いコメントを表示
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 件のコメント
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
2017 年 10 月 1 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!