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 an 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 function-call Inport blocks
2, 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 must be monotonically increasing and of double data type.
If the sample time for a function-call Inport block is specified, the values in the corresponding time vector must all be integer multiples of 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,
t1 = [0.1 0.1
0.1 0.5 0.5]'.
To use nonperiodic sample times, set the Inport block
Sample time to
-1 and provide a nonuniform
time vector, e.g.
t1 = [0, 0.1, 0.2, 0.4, 0.8].
Create a matrix with time steps and data values for data 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 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 the MATLAB workspace.
On the Modeling tab, select Model Settings
. In the Configuration Parameters dialog box, select the
Data Import/Export pane and set the
Input parameter to
t1, t2, d3.
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 the sample time of
0.1 specified in Inport block
t1 = [0:0.5:10]';
After you test your model, you can generate code for the functions. See Generate Code for Export-Function Model.