Load 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 Editor 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 (not supported by Signal Editor block)

  • Empty matrix — Use an empty matrix for ports for which you want to use ground values, without having to create data values

  • Time expression (not supported by Signal Editor block)

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 Forms of Input 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 box, 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 Editor Block for Test Case

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

  • Create a signal interactively

  • Import a signal from a MAT-file

  1. Create a model with Signal Editor, Gain, and Scope blocks.

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

    scenario = Simulink.SimulationData.Dataset;
    time = [0 1 1 5 5 8 8 10];
    data = [0 0 2 2 2 3 3 3]';
    scenario{1} = timeseries(data,time);
    scenario{1}.Name = 'var';
    save var.mat scenario
    
  3. Open the Signal Editor dialog box by double-clicking the Signal Editor block.

  4. In the File name parameter, enter var.mat.

  5. In the Active scenario parameter, select scenario. Click OK.

    The Scope block display reflects the test case data from the MAT-file.

Related Examples

More About