Matlab has a function called setappdata
. From this book (the chapter about caching) I have learned that cached data can be stored using setappdata
in a mysterious object 0 like this:
setappdata(0,'CachedData',[0 1 2 3]) % I am caching vector [0 1 2 3]
The question is, what is object 0?
You have discovered the Matlab root object, 0
.
All matlab GUI objects have handles
- including the root, which is 0.
Prior to R2014b all graphics handles were represented by what appeared to be a number, but infact was a pointer to the graphics handle.
You will find that all GUI that you create has the ability to store appdata.
Setting data in the 0 object -> this will mean that you can get it from anywhere (but it can also be overwritten from anywhere...) -> so its best to store data linked to your application:
hFig = figure;
setappdata ( hFig, 'variableName', yourVariable )
To get the data you use:
cache = getappdata(0,'CashedData')
% or post R2014b you can use:
cache = getappdata(groot,'CashedData')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With