Main Content

Simulink.sdi.registerCursorCallback

Register callback for cursor movements in the Simulation Data Inspector

Since R2021a

    Description

    callbackID = Simulink.sdi.registerCursorCallback(func) registers the callback function associated with the function handle func with the Simulation Data Inspector. The Simulation Data Inspector executes the callback when you move a cursor or change the number of cursors displayed on the Inspect pane.

    example

    callbackID = Simulink.sdi.registerCursorCallback(func,view) registers the callback function associated with the function handle func with the Simulation Data Inspector. The Simulation Data Inspector executes the callback when you move a cursor or change the number of cursors displayed on the pane specified by view.

    example

    Examples

    collapse all

    You can use a Simulation Data Inspector cursor callback function to send cursor position data to an app you build using the App Designer. This example shows how to add a property to the app to store the callback ID and where to register and unregister the cursor callback. For an example of an App Designer app that uses a cursor callback, see Synchronize Cursors in the Simulation Data Inspector with an App Designer App.

    Add a callbackID property to the app object.

    properties (Access = private)
        callbackID
    end

    Define the behavior of the cursor callback function.

    methods (Access = public)
        function myCursorCallback(app,~,~)
            if isvalid(app)
                ...
            end
        end
    end

    Register the cursor callback in the app startupFcn. This example registers the same callback on the Inspect pane and the Compare pane.

    function startupFcn(app)
        app.callbackID = Simulink.sdi.registerCursorCallback(...
           @(t1,t2)myCursorCallback(app,t1,t2));
        app.callbackID(2) = Simulink.sdi.registerCursorCallback(...
           @(t1,t2)myCursorCallback(app,t1,t2),'compare');
        ...
    end

    Unregister the cursor callback in the app UIFigureCloseRequest function.

    function myAppUIFigureCloseRequest(app, event)
        Simulink.sdi.unregisterCursorCallback(app.callbackID(1));
        Simulink.sdi.unregisterCursorCallback(app.callbackID(2));
        
    end

    Input Arguments

    collapse all

    Cursor callback to register, specified as a function handle. The function that corresponds to the function handle must accept two input arguments, t1 and t2, that correspond to the left and right cursor positions. When no cursors are displayed, t1 and t2 are NaN. When only one cursor is displayed, t2 is NaN.

    Example: id = Simulink.sdi.registerCursorCallback(@(t1,t2)myFunc(t1,t2)) registers the function myFunc as the callback for cursor events on the Inspect pane of the Simulation Data Inspector.

    Data Types: function_handle

    Cursor event source, specified as 'inspect' or 'compare'.

    • 'inspect' — Register callback for cursor events on the Inspect pane.

    • 'compare' — Register callback for cursor events on the Compare pane.

    The registered cursor callback executes for each cursor event. Cursor events occur when you move cursors or change the number of visible cursors.

    Data Types: char | string

    Output Arguments

    collapse all

    Registered callback ID, returned as a scalar. Use the callback ID to unregister the callback.

    Version History

    Introduced in R2021a