Simulate Simulink Model by Using MATLAB Language

Run a simulation of the Simulink® model to observe the non-real-time behavior of the model.

This procedure uses the Simulink model ex_slrt_nrt_osc (open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_nrt_osc')))). Before you run the simulation, loaded this model. From the Modeling tab, click Model Settings. Enable Data Import/Export > Time variable tout and enable Data Import/Export > Outputvariable yout.

  1. In the MATLAB Command Window, type:

    output=sim('ex_slrt_nrt_osc','SimulationMode','normal');

    The signal from the signal generator is logged to memory through the Outport block.

  2. After Simulink finishes the simulation, type:

    plot(output.get('tout'), output.get('yout'))

    MATLAB® opens a plot window and displays the output response.

When the real-time application is running in Real-Time mode, data is saved in the target computer memory. You retrieve the data through the target object properties tg.TimeLog, tg.StateLog, and tg.OutLog. In the Configuration Parameters dialog box, you must still select the Time, States, and Output check boxes for data to be logged to the target object properties.

See Also

Related Topics