Use the simulink.multisim.ExternalInput function and simulink.multisim.Variable to specify external data and variables for the simulation configuration stored in a simulink.multisim.DesignStudy object. Then, create a parameter space with exhaustive combinations of the external input data and variables. Finally, run the simulation using the simulink.multisim.DesignStudy object.
Open the model LoadInputData. The model contains one Inport block that is connected to a Gain block with a Gain value set as variable 'g'. The output of the Gain block is connected to an Outport block.
Create input data to load using the Inport block. For this example, create data that represents a sine wave using an evenly spaced vector of time values. Then, use the sin function to create a signal value for each time point.
You can specify external input data for top-level input ports using several formats. For this example, use the timeseries format. To create a timeseries, the time data must be a duration vector.
Use the simulink.multisim.ExternalInput function to add the external input data inData.
extIn =
ExternalInput with properties:
Values: [1×1 timeseries]
ProcessingFcn: @(x)x
You can also configure other aspects of the simulation using the Simulink.SimulationInput object, such as block parameter values, model configuration parameter values, and variable values.
Suppose you want to configure values for Gain block, and create a combination of external input values and gain values for the simulation. Use the simulink.multisim.Variable to specify a range of 10 values for the variable 'g'.
var =
Variable with properties:
Name: "g"
Values: [1 2 3 4 5 6 7 8 9 10]
Workspace: "global-workspace"
ProcessingFcn: @(x)x
An exhaustive combination of parameters is defined as all possible combination of two specified parameters. Use the simulink.multisim.Exhaustive function to create a parameter space that contains all combinations of the specified external input and variables.
exComb =
Exhaustive with properties:
ParameterSpaces: [1×2 simulink.multisim.SingleParameterSpace]
ds =
DesignStudy with properties:
ModelName: "LoadInputData_DesignStudy"
ParameterSpace: [1×1 simulink.multisim.Exhaustive]
PreSimFcn: @(simIn)simIn
PostSimFcn: @(simOut,simIn)simOut
NumSims: 10
Simulate the model using the configuration on the SimulationInput object.
[21-Apr-2025 15:57:21] Checking for availability of parallel pool...
[21-Apr-2025 15:57:21] Starting Simulink on parallel workers...
[21-Apr-2025 15:57:23] Configuring simulation cache folder on parallel workers...
[21-Apr-2025 15:57:23] Loading model on parallel workers...
[21-Apr-2025 15:57:26] Running simulations...