Import Data to Root-Level Input Ports

Root-Level Input Ports

You can import data from a workspace and apply it to a root-level:

  • Enable block

  • Inport block

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

    Note:   You cannot use input ports to import buses in Rapid Accelerator, RSim, or External modes.

You can also import data from a workspace using a From Workspace block. For details, see the From Workspace documentation and Import Data for an Input Test Case.

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

The software does not support this feature for other targets. For more information, see Set Up Rapid Simulation Input Data and Run Rapid Simulations.

Enable Data Import

To enable data import:

  1. Select the Configuration Parameters > Data Import/Export > Input parameter.

  2. Enter an external input specification in the adjacent edit box and click Apply.

    For details, see Input Data.

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.

Simulink® linearly interpolates or extrapolates input values as necessary if you select the Interpolate data option for the corresponding Inport, Enable, or Trigger block.

    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.

Forms of Input Data

The input data can take any of the following forms:

Input Expressions

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

Import Bus Data

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.

Was this topic helpful?