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 repectively.

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 object
  1x49 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×158
103 ×

    0.0130    0.0200    0.0210    0.0510    0.0520    0.0530    0.0630    0.0840    0.0850    0.0860    0.0870    0.0960    0.0970    0.0980    0.0990    0.1250    0.1260    0.1270    0.1280    0.1290    0.1340    0.1380    0.1410    0.1520    0.1530    0.1600    0.1610    0.1620    0.1630    0.1640    0.1650    0.1940    0.2010    0.2100    0.2110    0.2390    0.2430    0.2440    0.2480    0.2490    0.2500    0.2670    0.2700    0.2710    0.2980    0.3020    0.3030    0.3110    0.3120    0.3130

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

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

  948.0001  947.0001  949.0001  950.0001  951.0001

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;