Main Content

Tune Parameters by Using MATLAB Language

To change block parameters, you can use the MATLAB® functions. With these functions, you do not need to set the Simulink® interface to external mode or connect the Simulink interface with the real-time application.

You can download parameters to the real-time application while it is running or between runs. You can change parameters in your real-time application without rebuilding the Simulink model and change them back to their original values by using Simulink Real-Time™ functions.


Simulink Real-Time does not support parameters of multiword data types.

Access Parameters by Using Application Object

This procedure uses the Simulink model slrt_ex_osc. You must have already created and downloaded the real-time application to the default target computer.

  1. To create the target object and application object, in the MATLAB Command Window, type:

    tg = slrealtime('TargetPC1');
    app = slrealtime.Application('slrt_ex_osc');
  2. The Parameters property of the Application object is a structure that includes a BlockPath and BlockParameterName for each parameter. To display the parameter name of the first of parameter in the real-time application, in the MATLAB Command Window, type:

  3. To change the gain for the Gain1 block, type:

    pt = setparam(tg, 'Gain1', 'Gain', 800)
  4. The setparam method returns a structure that stores the source information, the previous value, and the new value.

    When you change parameters, the changed parameters in the target object are downloaded to the real-time application. The development computer displays this message:

    pt = 
           Source: {'Gain1'  'Gain'}
        OldValues: 400
        NewValues: 800
  5. The real-time application runs. The plot frame updates the signals for the active scopes.

  6. Stop the real-time application. In the Command Window, type:

  7. To reset to the previous values, type:

    pt = setparam(tg, pt.Source{1}, pt.Source{2}, pt.OldValues)
    pt = 
           Source: {'Gain1'  'Gain'}
        OldValues: 800
        NewValues: 400

Related Topics