Main Content

Scheduled 2-D AVI Recording with MATLAB

This topic describes how to schedule the recording of a 2-D animation using the MATLAB® interface for a virtual world that is associated with a Simulink® model. You control the animation file recording by presetting a time interval. The Simulink 3D Animation™ software records the animation during this interval in the simulation. In this example, the timing of the recorded animation file derives from the simulation time. One second of the recorded animation time corresponds to one second of Simulink time.

This procedure describes how to create an .avi animation file name with the default name format.

  1. Run the Simulink model for associated with the virtual world.

    The Simulink 3D Animation Viewer for that model is loaded and becomes active. If the viewer is not displayed, double-click the Simulink® 3D Animation block in the Simulink model.

  2. Retrieve the virtual world handle. Use the vrwhos command. Type

    vrwhos
    

    If the result indicates that only one vrworld object is in the workspace, assign its handle directly to a variable. Type

    myworld = 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);
    
  3. To retrieve the handle to the currently displayed Simulink 3D Animation Viewer figure, type

    f=get(myworld,'Figures')
    
  4. To have the Simulink 3D Animation software manually record the animation, set the RecordMode property to manual. Type

    set(myworld,'RecordMode','scheduled');
    
  5. Direct the Simulink 3D Animation software to record the animation as an .avi format file. Type

    set(f,'Record2D','on');
    
  6. Select the start and stop times during which you want to record the animation. For example, enter 5 as the start time and 15 as the stop time.

    set(myworld,'RecordInterval',[5 15]);
    

    Ensure that the recording start time value is not earlier than the start time of the Simulink model; the recording operation cannot start in this instance. If the stop time exceeds the stop time of the Simulink model, or if it is an out of bounds value such as a negative number, the recording operation stops when the simulation stops. The recording can be slow.

  7. 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');
    
  8. Ensure that the virtual reality figure window is the topmost window.

  9. 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 the simulation.

    • From the toolbar, click Start/pause/continue simulation to start the simulation.

    • From the keyboard, press Ctrl+T to start the simulation.

    The simulation runs. The Simulink 3D Animation software starts recording when the simulation time reaches the specified start time. The software creates a file .avi in the current working folder when finished, where N is either 1 or more, depending on how many file iterations you have.

  10. When you are done, 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.

  11. If you want to enable the navigation panel again, type

    set(f,'NavPanel','halfbar');
    
  12. Close and delete the objects if you do not want to continue using them.

Related Examples

More About