Main Content

isappdata

Determine if application data exists

    Description

    tf = isappdata(obj,name) determines whether the specified application data exists. The function returns 1 (true) if these conditions are met:

    • The application data has the specified name value.

    • The application data is associated with the UI component obj.

    Otherwise, isappdata returns 0 (false). The return result tf is of data type logical.

    example

    Examples

    collapse all

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

    Store the contents of d by using the setappdata function. In this case, store d in the figure using the name identifier 'todaysdate'.

    f = figure;
    d = date
    d = 
    '20-Jul-2024'
    
    setappdata(f,'todaysdate',d);

    Confirm that d is stored in the figure object under the specified name identifier.

    isappdata(f,'todaysdate')
    ans = logical
       1
    
    

    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
    colors = 1x3 cell
        {'Red'}    {'Yellow'}    {'Blue'}
    
    

    Input Arguments

    collapse all

    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 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.

    Version History

    Introduced before R2006a