setappdata

Stores user specified application data in an object.

Syntax

setappdata(handle, dataname, datavalue)

Inputs

handle
Handle of the object associated with the data dataname. The application data are stored in a structure.
Type: double
dataname
Name of the data to set.
Type: string
datavalue
Value of the data.
Type: [any]

Examples

setappdata is used to set user specified data to any object:
f = figure;
subplot(1, 2, 2);
lh = plot(1:10);
ph = uipanel('position',[0.02 0.1 0.4 0.4],'units','normalized');
bh = uicontrol(ph,'string', 'Text','position',[0.1 0.2 0.5 0.1],'units','normalized');

setappdata(f, 'data1', 1)
setappdata(lh, 'data1', 2)
setappdata(ph, 'data1', 3)
setappdata(bh, 'data1', 4)
Each object may have multiple entries in the application data structure:

f = figure;

setappdata(f, 'data1', 1)
setappdata(f, 'data2', [1:10])