run
Description
run(
runs the cosimulation with sampling period specified in
world
,sampleTime
)sampleTime
.
run(
additionally specifies the simulation time in world
,sampleTime
,simulationTime
)simulationTime
.
Examples
Create World and Actor
This example shows how to create an actor in a virtual world to display in the Simulation 3D Viewer window using Simulink® or MATLAB®.
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 actor, see Build Actor from 3D Graphic Primitives.
Create Virtual World with Actor Using Simulink
You can use the Simulation 3D Actor block and Simulation 3D Scene Configuration block to create an actor in a virtual world and view it in the Simulation 3D Viewer window.
Open Model
Open the Simulink model.
open_system("CreateWorld");
Explore Model Components
The model includes a Simulation 3D Scene Configuration block and a Simulation 3D Actor block. The Simulation 3D Scene Configuration block implements a 3D simulation environment. Double-click the Simulation 3D Scene Configuration block to open the Block Parameters dialog box. Set a view in the scene with the Scene view parameter. You can also set a custom viewpoint with this parameter. You must include the configuration block when building Simulink models with Simulation 3D Actor blocks.
The Simulation 3D Actor block adds an actor to the virtual world. Double-click the Simulation 3D Actor block to open the Block Parameters dialog box. To create an actor before simulation starts, on the Main tab, set the Operation parameter to Create at setup
. The block first creates an empty actor with the name specified in the Actor name parameter. You can use any name for the actor. Then, the block loads the source file, if any is present, and runs the Initialization script to build an appearance for the actor. For more details, see Operating Modes. For this example, the block does not build an appearance for the actor in the virtual world.
Simulate Model
Simulate the model and view the virtual world in the Simulation 3D Viewer.
sim("CreateWorld");
Close Model
Close the Simulink model.
close_system("CreateWorld");
Create Virtual World with Actor Using MATLAB
You can use the sim3d.World
and sim3d.Actor
objects to create an actor in a virtual world and view it in the Simulation 3D Viewer window.
Create World
Create a world scene.
world = sim3d.World();
Create Actor
Add an actor to the world.
add(world,sim3d.Actor());
Run Simulation
Run a simulation set for 10
seconds with a sample time of 0.02
seconds.
run(world,0.02,10)
Delete World
Delete the world object.
delete(world);
Input Arguments
world
— World object
sim3d.World
object
The sim3d.World
object where cosimulation is being run.
sampleTime
— Sampling period of world
0.02 | scalar
Sampling period of the virtual reality world, specified as a real positive scalar.
Data Types: single
simulationTime
— Length of time of simulation
inf | scalar
Length of time the simulation runs, specified as a real positive scalar.
Data Types: single
Version History
Introduced in R2022b
See Also
sim3d.World
| sim3d.Actor
| findBy
| propagate
| gather
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)