run
Description
Examples
Create World and Actor Using MATLAB
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
Create an actor object. The sim3d.Actor
object creates an empty actor without any visual meshes.
actor = sim3d.Actor();
Add the actor to the world.
add(world,actor);
Run Simulation
Run a simulation set for 10
seconds with a sample time of 0.02
seconds.
sampletime = 0.02; stoptime = 10; run(world,sampletime,stoptime);
Delete World
Delete the world object.
delete(world);
Input Arguments
world
— World object
sim3d.World
object
World object where co-simulation is being run, specified as a
sim3d.World
object.
sampleTime
— Sample time of simulation
0.02
| real positive scalar
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
stopTime
— Simulation stop time
10
| real positive scalar
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
pauseTime
— Time until simulation pauses
inf
(default) | real positive scalar
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
Note
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 R2022bR2024a: Set the simulation duration using stopTime
, renamed from simulationTime
Use the stopTime
argument to specify the length of time the
simulation runs. Previously, simulationTime
specified the length of time
the simulation runs.
R2024a: Set the duration after which the simulation pauses
Use the pauseTime
argument to specify the length of time the
simulation runs before pausing.
See Also
sim3d.World
| sim3d.Actor
| save
| createViewport
| add
| remove
| pause
| resume
| close
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)