Main Content


Run co-simulation with the 3D simulation engine

Since R2022b



    run(world,sampleTime) runs the co-simulation with sample time specified in sampleTime.

    run(world,sampleTime,stopTime,pauseTime) additionally specifies the stop time in stopTime and pause time in pauseTime.


    collapse all

    This example shows how to create a 3D environment with an empty actor and view in the Simulation 3D Viewer window using MATLAB®. You can use the sim3d.World to create a world object and sim3d.Actor to create an empty actor object. You can then add the actor to the 3D environment and visualize the 3D environment in the Simulation 3D Viewer window. For an example that shows how to create a 3D environment with an actor using Simulink®, see Create World and Actor Using Simulink.

    This process does not build an appearance for the actor, so the Simulation 3D Viewer does not render a visualization of the actor. For an example that shows how to build an appearance for an empty actor, see Build Actor from 3D Graphic Primitives Using MATLAB.

    Create World

    Create a world object.

    world = sim3d.World();

    Create Actor

    Add an actor to the world.


    Run Simulation

    Run a simulation set for 10 seconds with a sample time of 0.02 seconds.


    Empty virtual world scene

    Delete World

    Delete the world object.


    Input Arguments

    collapse all

    World object where co-simulation is being run, specified as a sim3d.World object.

    Sample time of simulation, Ts, specified as a real positive scalar, in s. Sample time refers to the time interval at which the output is updated during the simulation. The simulation speed depends on the model complexity, computational speed, and the type of prebuilt scene rendered. A smaller sample time allows frequent computations, which increases computational load and reduces simulation speed. A larger sample time reduces the computational load and increases the speed of the simulation. The graphics frame rate of the 3D simulation engine is the inverse of the sample time. For example, if sample time is 1/50, then the 3D simulation engine solver tries to achieve a frame rate of 50 frames per second. However, the real-time graphics frame rate is often lower due to factors such as graphics card performance and model complexity.

    Data Types: single

    Simulation stop time, specified as a real positive scalar, in s. Stop time refers to the time at which the simulation is set to end. You can specify stop time as inf to run a simulation until you stop it by closing the game window.

    Data Types: single

    Time until simulation pauses, specified as a real positive scalar, in s. Pause time refers to the duration after which the simulation stops updating its state. You can set a value for pause time to pause the simulation. When the simulation is paused, you can analyze, debug, or troubleshoot your model performance.

    Data Types: single


    Setting the sampleTime, stopTime and pauseTime values using the run function overwrites the sample time and stop time values set using the sim3d.World object.

    Version History

    Introduced in R2022b

    expand all