Documentation

getappdata

Retrieve application-defined data

Use the getappdata function to retrieve data stored using the setappdata function. Both of these functions provide a convenient way to share data between callbacks or between separate UIs.

Syntax

Description

example

val = getappdata(obj,name) returns a value stored in the graphics object, obj. The name identifier, name, uniquely identifies the value to retrieve.

example

vals = getappdata(obj) returns all values stored in the graphics object with their name identifiers.

Examples

collapse all

Store and Retrieve Date and Time

Create a figure window.

f = figure;

Get the current date and time as separate variables.

dt = fix(clock);
currdate = dt(1:3);
currtime = dt(4:6);

Store currdate and currtime using the setappdata function.

setappdata(f,'todaysdate',currdate);
setappdata(f,'presenttime',currtime);

Retrieve the date information.

getappdata(f,'todaysdate')
ans =

    2014  12    23

Retrieve all data associated with figure f.

getappdata(f)
ans = 

     todaysdate: [2014 12 23]
    presenttime: [16 51 5]

Input Arguments

collapse all

obj — Graphics object containing the valuefigure | uipanel | uibuttongroup | uicontrol | ...

Graphics object containing the value, specified as any graphics object (except an ActiveX® component). This is the same graphics object passed to setappdata during the storage operation.

name — Name identifierstring

Name identifier, specified as a string value. This is the same name identifier passed to setappdata during the storage operation.

Data Types: char

Output Arguments

collapse all

val — Stored valueany MATLAB® data type

Stored value, returned as the same value and data type that was originally stored.

vals — All values stored in the graphics object with name identifiersstruct

All values stored in the graphics object with name identifiers, returned as a struct. Each field in the struct corresponds to a stored value. The field names of the struct correspond to the name identifiers assigned when each value was stored.

Introduced before R2006a

Was this topic helpful?