setappdata - Store application data - MATLAB (original) (raw)
Main Content
Syntax
Description
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](#f51-1526-obj),[name](#f51-1526-name),[val](#f51-1526-val))
stores the contents of val
. The graphics object,obj
, and the name identifier, name
, uniquely identify the data for later retrieval.
Examples
Create a figure window. Then, get the current time using thedate
function.
Store the contents of val
using thesetappdata
function. In this case,val
is stored in the figure object using the name identifier, 'todaysdate'
.
setappdata(f,'todaysdate',val);
Retrieve the data and display it.
getappdata(f,'todaysdate')
Input Arguments
Graphics object in which to store the value, specified as any graphics object. 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 or string scalar. 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 value5
using the name'mydata'
.
Value to store, specified as any MATLAB data type.
Version History
Introduced before R2006a