Main Content

Observe Impact of Simulink Parameters Using Model Slicer

Use Model Slicer to observe the impact a parameter has on a model.

This example demonstrates the ability of Model Slicer to display the parameters that affect a block (Option 1), and blocks that are affected by a parameter (Option 2) using the methods of the SLSlicerAPI.ParameterDependence class parametersAffectingBlock, and blocksAffectedByParameter respectively.

Open Model and Initialize ParameterDependence Class

1. Open the model sldvSliceCruiseControl.

model = 'sldvSliceCruiseControl';
open_system(model);

2. Create an object of the ParameterDependence Class.

slicerObj = slslicer(model);
pd = slicerObj.parameterDependence;

Option 1: Find Parameters Affecting a Block

1. View the parameters that affect the Switch3 block in the DriverSwRequest subsystem by entering:

params = parametersAffectingBlock(pd, 'sldvSliceCruiseControl/DriverSwRequest/Switch3')
params=1×49 VariableUsage array with properties:
    Name
    Source
    SourceType
    Users

You can see that there are 49 parameters that affect the Switch3 block. To view the details of individual parameters, explore each element of the array:

params(1)
ans = 
  VariableUsage with properties:

          Name: 'CountValue'
        Source: 'sldvSliceCruiseControl/DriverSwRequest/decrement/counter'
    SourceType: 'mask workspace'
         Users: {'sldvSliceCruiseControl/DriverSwRequest/decrement/counter/Constant'}

Option 2: Get Blocks Affected by a Parameter

1. To observe the impact of a parameter, create a Simulink.VariableUsage object for that parameter.

param = Simulink.VariableUsage('CountValue','sldvSliceCruiseControl/DriverSwRequest/decrement/counter');

2. To view all the blocks affected by param:

affectedBlocks = blocksAffectedByParameter(pd, param)
affectedBlocks = 1×153
103 ×

    0.1760    0.3180    0.3230    0.3860    0.3900    0.3940    0.4080    0.4550    0.4600    0.4650    0.4700    0.4910    0.4950    0.4990    0.5030    0.5330    0.5380    0.5430    0.5480    0.5530    0.5690    0.5830    0.5920    0.6120    0.6190    0.6350    0.6390    0.6430    0.6470    0.6510    0.6550    0.6920    0.7060    0.7240    0.7280    0.7660    0.7780    0.7820    0.7920    0.7960    0.8000    0.8260    0.8340    0.8380    0.8800    0.8920    0.9000    0.9180    0.9220    0.9260

You can further refine the blocks affected using the same options supported by find_system.

affectedOutports = blocksAffectedByParameter(pd, param, 'blockType', 'Outport')
affectedOutports = 1×5
103 ×

    2.0630    2.0610    2.0650    2.0670    2.0690

Optional Step: Highlight Result on Model by Using Model Slicer

You can view the active section of the analyzed model by using the Model Slicer highlighting.

slicerObj.highlight(slicerObj.ActiveConfig);

Clean Up

Model Slicer maintains the model in compiled state after analysis. To close the model, terminate the slicerObj object.

slicerObj.terminate;