Object with handle 0 in Matlab

Matlab has a feature called setappdata. From this book (the chapter on caching), I learned that cached data can be saved using setappdatathe mysterious object 0 as follows:

setappdata(0,'CachedData',[0 1 2 3]) % I am caching vector [0 1 2 3]

The question is, what is object 0?

+4
source share
1 answer

You have found the Matlab object root, 0.

All GUI objects in Matlab have handles- including a root equal to 0.

Prior to R2014b, all graphic descriptors were represented by what represented by a number, but infact was a pointer to a graphic descriptor.

You will find that the entire graphical interface that you create has the ability to store appdata.

0 → , ( ...) → , :

hFig = figure;
setappdata ( hFig, 'variableName', yourVariable )

, :

cache = getappdata(0,'CashedData')

% or post R2014b you can use:
cache = getappdata(groot,'CashedData')
+8

Source: https://habr.com/ru/post/1629569/


All Articles