When function-call sequencing is simple enough to be specified as a model input, simulation using an input matrix is the preferred method for testing an export-function model.
Create time vectors that specify function-call times.
Create a matrix that adds input data to the time vectors.
To create the model in this example, see Create Export-Function Model.
Create time-vectors indicating when events occur for root-level function-call Inport blocks and data-vectors for root-level data Inport blocks.
For Inport 1 and Inport 2 blocks, create column
vectors with time steps of
0.01. In the
MATLAB Command window, enter
t1 = [0:0.1:10]' t2 = [0:0.01:10]'
The time vector data type must be double and monotonically increasing.
If Sample time for a function-call Inport block is specified, the time vector must be a periodic series increasing with the specified value.
To specify multiple function-calls at a given time step, repeat the time value
accordingly. For example, to specify three events at t = 0.1 and 2 events at t =
0.5, list 0.1 three times and 0.5 twice in your time vector,
t = [0.1 0.1
0.1 0.5 0.5]'.
If you want to use a nonperiodic time vector, set the Inport
block Sample time to
-1 and provide a
nonperiodic time vector, t1 = [0, 0.1, 0.2, 0.4, 0.8]
Create a matrix with time steps and data values for Inport block
sine_data = sin(0:0.01:10)' d3 =[t2,sine_data]
The data input can use any supported format as described in Forms of Input Data.
The following table provides additional information for specifying the time vector
|Sample time type for internal Trigger Port block set to:|
Root-level Function-Call Inport block with inherited sample time (-1)
Root-level Function-Call Inport block with discrete sample time
Nondecreasing column vector.
The function-call subsystem executes at the times specified by the column vector. The sample times can be periodic or aperiodic.
If you specify an empty matrix
Nondecreasing column vector. Each element in the column vector must be an integer multiple of the sample time specified by the Inport block.
The function-call subsystem executes at the times specified by the column vector.
Alternatively, specify an empty matrix
Configuration not allowed.
The the function-call subsystem executes at the times specified by the Inport block calling it.
Simulate the export-function model to test and observe its behavior before generating code.
Import time and data from MATLAB® workspace. In the Configuration Parameters > Data Import/Export pane, set the Input parameter to
t2 are column vectors containing event
times for the function-call Inport blocks
d3 is a table of input values versus time for
the data Inport block
Plot results. In the MATLAB Command Window, enter.
plot(yout.time, yout.signals(1).values) hold plot(yout.time, yout.signals(2).values)
t1 to provide events every
0.5 is an integer multiple of
0.1 specified in
the Inport block 1.
t1 = [0:0.5:10]'
After you test your model, you can generate code for the functions. See Generate Code for Export-Function Model.