Use application data to determine the value to assign to a variable.
Create a figure window and specify val. Store the contents of val in the figure object using the name identifier 'primary'.
f = figure;
val = {'Red','Yellow','Blue'};
setappdata(f,'primary',val);
Set the variable colors to a value that depends on the presence of application data by using conditional statements.
If there exists data associated with the name identifier 'primary' in the figure, assign this data to colors. Otherwise, assign new data to colors. Print the value of colors.
if isappdata(f,'primary')
colors = getappdata(f,'primary')
else
colors = {'Orange','Green','Purple'}
end
obj — Graphics object storing the data Figure object | Panel object | ButtonGroup object | UIControl object | ...
Graphics object storing the data, specified as any graphics object. This object is
the same graphics object passed to setappdata during the storage
operation.
name — Name identifier character vector | string scalar
Name identifier of the data, specified as a character vector or string scalar. This
identifier is the same name identifier passed to setappdata during
the storage operation.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.