Import Data for an Input Test Case

For most input test cases, you try to minimize the number of time points. The signal data you load includes samples with ramps and discontinuities.

Guidelines for Importing a Test Case

Typically when importing a test case data, you want to minimize the number of time points. The test data focuses on discontinuities in the signal data.

  • Create a signal that has ramps and steps. In other words, the signal has one or more discontinuities.

  • Create the signal using the fewest points possible.

  • Have the Simulink® solver execute at the specified discontinuities.

To import this signal in Simulink, use a From Workspace, From File, or Signal Builder block, all of which support zero-crossing detection.

You can load data of these types:

  • A Simulink.SimulationData.Dataset

  • Array

  • Simulink.SimulationData.Signal

  • Structure

  • 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

Specify a time vector and signal values, but specify only the time steps at points where the shape of the output jumps. For details about specifying a time vector, see Specify Time Data.

Use any of the input data formats described in Loading the Data, except for MATLAB® time expressions.

Example of Test Case Data

The following is an example of test case data:

The following two examples use this test case data.

Use From Workspace Block for Test Case

  1. Open the model ex_data_import_test_case_from_workspace.

  2. Enable zero-crossing detection. In the From Workspace block dialog, select Enable zero-crossing detection. Zero-crossing detection allows you to capture discontinuities accurately.

  3. Create a signal structure for the test case. At each discontinuity, enter a duplicate entry in the time vector, which generates a zero crossing and forces the variable-step solver to take a time step at this exact time. For details, see Load Data Using the From Workspace Block.

    Define the var structure representing the test case:

    var.time = [0 1 1 5 5 8 8 10];
    var.signals.values = [0 0 2 2 2 3 3 3]';
    var.signals.dimensions = 1;
  4. To import the test case structure, in the From Workspace block dialog box, in the Data parameter, specify var.

  5. Simulate the model. The Scope block reflects the test case data.

Use Signal Builder Block for Test Case

Instead of using a From Workspace block, you can use a Signal Builder block to either:

  • Create a signal interactively

  • Import a signal from a MAT-file

  1. Open the ex_data_import_signal_builder model.

  2. Create a structure and save it in a MAT-file:

    var.time = [0 1 1 5 5 8 8 10];
    var.signals.values = [0 0 2 2 2 3 3 3]';
    var.signals.dimensions = 1;
    var.signals.label = 'var';
    save var.mat var
  3. Open the Signal Builder dialog box by double-clicking the Signal Builder block.

  4. Select File > Import From File menu item, and select the var.mat file.

  5. In the Select parameter, select Replace existing dataset. In the Data to Import section, select the Select All check box. Confirm the selection and click OK.

    The Signal Builder block display reflects the test case data.

Related Examples

More About

Was this topic helpful?