Main Content

Pass Dialog Parameters to S-Functions

You can pass parameters to an S-function at the start of and during the simulation, using the S-function parameters field of the Block Parameters dialog box. Such parameters are called dialog box parameters to distinguish them from run-time parameters created by the S-function to facilitate code generation (see Create and Update S-Function Run-Time Parameters).

Note

You cannot use the Model Explorer, the S-function Block Parameters dialog box, or a mask to tune the parameters of a source S-function, i.e., an S-function that has outputs but no inputs, while a simulation is running. For more information, see Tune and Experiment with Block Parameter Values.

Using Level-2 MATLAB S-Function Dialog Parameters

The Simulink® engine stores Level-2 MATLAB® S-function dialog parameters in the block run-time object. To use dialog parameters in a Level-2 MATLAB S-function, perform the following steps when you create the S-function:

  1. Determine the order in which the parameters are to be specified in the block's dialog box.

  2. In the setup method, set the run-time object's NumDialogPrms property to indicate to the engine how many parameters the S-function accepts, for example:

    block.NumDialogPrms = 2;
  3. Access the dialog box parameters in the S-function using the run-time object's DialogPrm method. The dialog parameter's Data property stores its current value, for example:

    param1 = block.DialogPrm(1).Data;
    param2 = block.DialogPrm(2).Data;

When running a simulation, you must specify the parameters in the Parameters field of the Level-2 MATLAB S-Function Block Parameters dialog in the same order that you defined them in step 1.

Tunable Parameters

Dialog box parameters can be either tunable or nontunable. A tunable parameter is a parameter that a user can change while the simulation is running.

Note

Dialog box parameters are tunable by default. Nevertheless, it is good programming practice to set the tunability of every parameter, even those that are tunable. If you enable the simulation diagnostic S-function upgrades needed, the Simulink engine issues the diagnostic whenever it encounters an S-function that fails to specify the tunability of all its parameters.

In a Level-2 MATLAB S-function, set the run-time object DialogPrmsTunable property in the setup method to specify the tunability of each S-function dialog box parameter. For example, the following line sets the first parameter of an S-function with three dialog parameters to tunable, and the second and third parameters to nontunable.

block.DialogPrmsTunable = {'Tunable','Nontunable','Nontunable'};

See Also

| | |

Related Topics