Main Content

removeObserver

Remove observer from scenario simulation

    Description

    example

    removeObserver(ScenarioSim,ObserverName) removes the observer named ObserverName from the Simulink.ScenarioSimulation object ScenarioSim.

    Examples

    Remove Observer from Scenario Simulation

    Create ScenarioSim, a Simulink.ScenarioSimulation object.

    rrApp = roadrunner('C:\RoadRunnerProject');
    openScenario(rrApp,'TrajectoryCutIn');
    ScenarioSim = createSimulation(rrApp);
    

    Create the class mySysObserver, which inherits from matlab.System base class. The mySysObserver class represents an observer.

    classdef mysysObserver < matlab.System
    
    properties(Access=private)
    % …
    end
    methods
    % constructor for the System object
    function obj = mysysObserver()
    end
    end
    
    
    methods(Access = protected)
    
    %reset the values
    function resetImpl(obj)
    obj.mScenarioSimObj = Simulink.ScenarioSimulation.find('ScenarioSimulation', 'SystemObject', obj);
    obj.mScenarioSimActorList = [];
    obj.mIsPacingTurnedOff = false;
    end
    
    
    
    % get the required parameter values
    function stepImpl(obj)
    mSimulationPace = obj.mScenarioSimObj.get('SimulationPace');
    mScenarioSimActorList = obj.mScenarioSimObj.get('ActorSimulation');
    end
    end
    end

    Add the observer to the scenario.

    obsStatus = addObserver(ScenarioSim,'ReadPaceandActors',mysysObserver);
    

    Remove the observer from the scenario.

    removeObserver(ScenarioSim,'ReadPaceandActors');

    Input Arguments

    collapse all

    RoadRunner Scenario simulation, specified as a Simulink.ScenarioSimulation object.

    Example: removeObserver(ScenarioSim, 'ObservingRedTruck')

    Name of observer to remove, specified as a string or character vector.

    Example: 'ObservingRedTruck'

    Version History

    Introduced in R2022a