Import Data for an Input Test Case

Guidelines for Importing a Test Case

Typically when importing a test case in Simulink®, you want to:

  • 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.

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 to Import an Input Test Case

  1. Open the model ex_data_import_test_case_from_workspaceex_data_import_test_case_from_workspace.

  2. Enable zero-crossing detection. In the From Workspace block dialog, select Enable zero-crossing detection.

  3. Create a signal structure for the test case. At each discontinuity, enter a duplicate entry in the time vector. As described in the From Workspace block documentation, this generates a zero-crossing and forces the variable-step solver to take a time step at this exact time.

    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, in the Data parameter, specify var.

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

Use Signal Builder Block to Import an Input Test Case

As an alternative to using a From Workspace block, you can use a Signal Builder block to either create a signal interactively or to import a signal from a MAT-file.

  1. Open the ex_data_import_signal_builderex_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. Double-click the Signal Builder block to open its dialog box.

  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.

For a detailed example that shows how to use a Signal Builder block as the input source for your model and to import your own signal data to the model, see Import Signal Data.

Was this topic helpful?