|On this page…|
You can import data from a workspace and apply it to a root-level:
Trigger block that has an edge-based (rising, falling, or either) trigger type
These blocks import data from the workspace based on the value of the Configuration Parameters > Data Import/Export > Input parameter.
If you want to import many signals to root-level input ports, see Import and Map Root-Level Inport Data.
If your target is an RSim target, you can import root-level inport data from workspace variables in a MAT-file using the following command:
!model -i ws_variables.mat
To enable data import:
Select the Configuration Parameters > Data Import/Export > Input parameter.
Enter an external input specification in the adjacent edit box and click Apply.
For details, see Input Data.
Use the Configuration Parameters > Data Import/Export > Input parameter to import data from a workspace and apply it to the root-level input ports of a model during a simulation run.
Note: The use of the Input box is independent of the setting of the Format list on the Data Import/Export pane.
Simulink resolves symbols used in the external input specification as described in Symbol Resolution. See the documentation of the sim command for some data import capabilities that are available only for programmatic simulation.
The input data can take any of the following forms:
MATLAB® timeseries — For details, see the following sections:
Array — See Import Data Arrays.
Simulink.SimulationData.Signal — For details, see Import Signal Logging Data
Structure — See Import Data Structures.
A structure array containing data for all input ports.
Empty matrix — Use an empty matrix for ports for which you want to use ground values, without having to create data values.
Time expression — See Import MATLAB Time Expression Data.
Simulink.Timeseries and Simulink.TsArray — See Import Simulink.Timeseries and Simulink.TsArray Data.
In the Input box, specify the signal input using either of these approaches:
Create data at runtime for each simulation time step using the input u = UT(t) for either a MATLAB function (expressed as a string) or MATLAB expression.
Specify the data directly, using either:
A 2D array of input values versus time for all input ports, in the form UT = [T, U1, ... Un], where T = [t1, ..., tm]'
A comma-separated list of variables or MATLAB expressions. For details, see Comma-Separated Lists for the Input Parameter.
Comma-Separated Lists for the Input Parameter. Each variable or expression corresponds to a specific input port. Each variable or expression in the list should evaluate to the appropriate object that corresponds to one of the root-level input ports of the model, with the first item corresponding to the first root-level input port, the second to the second root-level input port, and so on.
For an Enable or Trigger block, the signal driving the enable or trigger port must be the last item in the comma-separated list. If you have both an enable and a trigger port, then specify the enable port as the next-to-last item in the list, and the trigger port as the last item.
To simplify the specification of external data to input, you can load data for a subset of root-level Inport ports, without having to create data structures for the ports for which you want to use ground values. For information about ground values, see Initialize Signals and Discrete States.
Use an empty matrix to specify ground values for a port. For example, to load data for input ports in1 and in3, and to use ground values for port in2, enter the following in the Input parameter:
in1, , in3
To import bus data to root input ports, use a structure of MATLAB timeseries objects. For details, see Import Structures of timeseries Objects for Buses.
You can specify an empty matrix in a comma-separated list. The empty matrix uses the ground values for the bus signal.
For example, to load data for input ports in1 and in3, and to use ground values for port in2, enter the following in the Input parameter:
in1, , in3
You can initialize bus signals, including using partial specification of initialization data. For details, see Specify Initial Conditions for Bus Signals.
For details about importing array of bus data to a root Inport block, see Import Array of Buses Data.