This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Import Data to Test a Discrete Algorithm

Discrete signals are signals that you define using evenly-spaced time values. One signal value is read at each time step, using the sample time of the source block.

Use a structure that has an empty time vector, which results in the model using the sample time of the source block. Using this approach avoids possible mismatches between the vector and the Simulink® time steps. The double-precision rounding used by computers and the values expected by Simulink can differ.

Suppose you want to import signal data for this very simple model.

  1. In the Block Parameters dialog box for the Inport block:

    • Set the sample time.

    • Clear the Interpolate data parameter.

  2. For the data that you want to import, specify a structure variable that does not include a time vector. For example, for the variable called import_var:

    import_var.time = [];
    import_var.signals.values = [0; 1; 5; 8; 10];
    import_var.signals.dimension = 1;

    The input for the first time step is read from the first element of an input port value array. The value is 0. The value for the second time step is read from the second element of the value array (1), and so on.

    For details about how to specify the signal value and dimension data, see Specify Signal Data.

  3. Select the Configuration Parameters > Data Import/Export > Input parameter and specify import_var for the data to import.

If you are using a From Workspace block to import data, use a similar approach. In addition, set the Form output after final data value by parameter to a value other than Extrapolation.

Related Examples

More About

Was this topic helpful?