Main Content

schedulePostSimulationAction

Schedule post-simulation action

Since R2026a

    Description

    actionID = schedulePostSimulationAction(networkSimulator,callbackFcn,userData) schedules an action to be performed after the simulation completes. The callbackFcn argument specifies the action performed, and userData specifies the input data used for the specified action.

    example

    Examples

    collapse all

    Create a wireless network simulator, and define the duration of the simulation.

    simulator = wirelessNetworkSimulator.init;
    simulationDuration = 1;                    % Seconds

    Create a custom local function, actionCallback, that defines the action to be performed by the simulator.

    % Callback function
    function actionCallback(~,userData)
    % Print the action type and its execution timeStamp
    fprintf("t=%.3f seconds: ActionType=%s executed \n",userData.SimulatorObj.CurrentTime,userData.ActionType);
    end

    Schedule a pre-simulation action.

    userData = struct(ActionType="PreSimulationAction",SimulatorObj=simulator);
    schedulePreSimulationAction(simulator,@actionCallback,userData);

    Schedule a post-simulation action.

    userData = struct(ActionType="PostSimulationAction",SimulatorObj=simulator);
    schedulePostSimulationAction(simulator,@actionCallback,userData);

    Schedule a regular action for t = 0 seconds.

    This action executes after the pre-simulation action, even though the timestamps for both actions are t = 0 seconds.

    userData = struct(ActionType="FirstSimulationAction",SimulatorObj=simulator);
    scheduleAction(simulator,@actionCallback,userData,0);

    Schedule a regular action for t = simulationDuration.

    This action executes before the post-simulation action, even though the timestamps for both actions are t = simulationDuration.

    userData = struct(ActionType="LastSimulationAction",SimulatorObj=simulator);
    scheduleAction(simulator,@actionCallback,userData,simulationDuration);

    Create 5G nodes.

    gNB = nrGNB;
    ue = nrUE;

    Connect the user equipment (UE) and base station (gNB) nodes.

    gNB.connectUE(ue,FullBufferTraffic="on");

    Add the nodes to the wireless network simulator.

    addNodes(simulator,gNB);
    addNodes(simulator,ue);

    Run the simulation.

    run(simulator,simulationDuration);
    t=0.000 seconds: ActionType=PreSimulationAction executed 
    t=0.000 seconds: ActionType=FirstSimulationAction executed 
    t=1.000 seconds: ActionType=LastSimulationAction executed 
    t=1.000 seconds: ActionType=PostSimulationAction executed 
    

    Input Arguments

    collapse all

    Wireless network simulator, specified as a wirelessNetworkSimulator object.

    Callback function, specified as a function handle. The callback function is a custom function that defines an action to perform after the simulation completes. The syntax for the callback function must be:

    callbackFcn(actionID,userData)

    Input to the callback function, specified as a numeric value, character vector, or string scalar. If the callback function does not require any input, specify the userData value as []. To pass multiple values as input to the callback function, specify the input as a structure or a cell array.

    Output Arguments

    collapse all

    Unique identifier for the scheduled post-simulation action, returned as a positive integer.

    Version History

    Introduced in R2026a