Manual 2-D AVI Recording with MATLAB
This topic describes how to record a 2-D animation manually using the MATLAB® interface for a virtual world that is associated with a Simulink® model. In this example, the timing of the animation file derives from the simulation time. One second of the recorded animation time corresponds to one second of Simulink time. You create and record the animation file by interactively starting and stopping the recording from the MATLAB Command Window.
This procedure describes how to create an .avi animation file name with the default name format.
Run the Simulink model for associated with the virtual world. In the MATLAB window, type
The Simulink model appears. Also by default, the Simulink 3D Animation™ Viewer for that model is loaded and becomes active. If the viewer does not appear, double-click the Simulink® 3D Animation block in the Simulink model.
To work with the virtual world associated with model from the MATLAB interface, retrieve the virtual world handle. Use the
vrwhos
command. Typevrwhos
If the result indicates that only one
vrworld
object is in the workspace, assign its handle directly to a variable. Typemyworld = vrwho;
If multiple virtual worlds are listed, select which of these virtual worlds you want to manipulate. To select the virtual world, you can use indexing or a selection method using a string comparison of virtual world descriptions. For the indexing method, type
worlds = vrwho; myworld = worlds(1);
If the description string is unique,
myworld
is assigned the correct virtual world.Create a virtual reality figure and view the virtual world in the Simulink 3D Animation Viewer. Type
f=vrfigure(myworld);
To retrieve the handle to the currently displayed the Simulink 3D Animation Viewer figure, type
f=get(myworld,'Figures')
To have the software manually record the animation, set the
RecordMode
property tomanual
. Typeset(myworld,'RecordMode','manual');
Direct the Simulink 3D Animation software to record the animation as a
.avi
format file. Typeset(f,'Record2D','on');
Disable the navigation panel. The navigation panel appears at the bottom of the virtual scene view. You can turn off this panel for a cleaner view of the virtual scene. Type
set(f,'NavPanel','none');
Run the Simulink model. From the Simulation menu, select Mode > Normal, then click Simulation > Run. Alternatively, if you are using the Simulink 3D Animation default viewer, you can run the Simulink model with one of the following from the viewer:
From the menu bar, select the Simulation menu Start option to start or stop the simulation.
From the toolbar, click Start/pause/continue simulation to start the simulation.
From the keyboard, press Ctrl+T to start the simulation.
As the simulation runs, start recording the animation by setting the virtual world
Recording
property. Typeset(myworld,'Recording','on');
This setting turns on the recording state.
To stop the recording operation, type:
set(myworld,'Recording','off');
The Simulink 3D Animation software stops recording the animation. The Simulink 3D Animation software creates the file
.avi
in the current working folder. If the simulation stops before you stop recording, the recording operation stops and creates the animation file.Stop the simulation. You can use one of the following from the viewer.
From the menu bar, select the Simulation menu Stop option to stop the simulation.
From the toolbar, click Stop simulation to stop the simulation.
From the keyboard, press Ctrl+T to stop the simulation.
You do not need to stop the simulation manually. If you do not manually stop the recording, the recording operation does not stop and create the animation file until the simulation stops.
Close and delete the objects if you do not want to continue using them.
Related Examples
- Manual 3-D Recording with MATLAB
- Scheduled 3-D Recording with MATLAB
- Scheduled 2-D AVI Recording with MATLAB
- Record Animations for Unconnected Virtual Worlds
- Play Animation Files