This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Store application-defined data

Use this function to store data in a UI. You can retrieve the data elsewhere in your code using the getappdata function. Both of these functions provide a convenient way to share data between callbacks or between separate UIs.





setappdata(obj,name,val) stores the contents of val. The graphics object, obj, and the name identifier, name, uniquely identify the data for later retrieval.


collapse all

Create a figure window. Then, get the current time using the date function.

f = figure;
val = date
val =


Store the contents of val using the setappdata function. In this case, val is stored in the figure object using the name identifier, 'todaysdate'.


Retrieve the data and display it.

ans =


Input Arguments

collapse all

Graphics object in which to store the value, specified as any graphics object (except an ActiveX® component). The graphics object must be accessible from within the functions you plan to store and retrieve the data.

Name identifier, specified as a character vector. Select a unique name identifier that is easy to remember so that you can easily recall it when you want to retrieve the data.

Example: setappdata(h,'mydata',5) stores the value 5 using the name 'mydata'.

Data Types: char

Value to store, specified as any MATLAB data type.

Introduced before R2006a