Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object with handle 0 in Matlab

Tags:

matlab

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?

like image 674
Sergey Zykov Avatar asked Feb 07 '23 17:02

Sergey Zykov


1 Answers

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')
like image 111
matlabgui Avatar answered Feb 16 '23 08:02

matlabgui