Main Content

Provide Signal Data for Simulation

A Simulink® model performs algorithms on input signal data and produces output signals. The model defines what input data to use at the start of simulation and what output to capture at the end of simulation. As you create and simulate your model, you:

As you create, debug, and test a model, you can use different sets of input signal data for simulation. You can use logged simulation data as input to another simulation.

Identify Model Signal Data Requirements

To use system-generated signal data, use source blocks such as a Sine Wave block. Source blocks do not require the use of a variable or external data source. If you cannot configure source blocks to meet your modeling requirements, then supply the signal data.

As you determine your signal data requirements, identify the:

  • Blocks (including subsystems and Model blocks) that you need to provide data for — Design interfaces for blocks and for model components, including data types of signals.

  • Range characteristics of signals, such as sample time, dimensions, and data type.

  • Storage location for data for each input signal — Determine where to store signal data: in workspace variables, a MAT-file, or an external data file such as an Microsoft® Excel® spreadsheet.

Create a list of equation variables and constant coefficients, and then determine the coefficient values from published sources or by performing experiments on the system.

For information about storage locations for signal data, see Signal Data Storage for Loading.

Signal Data Storage for Loading

Store signal data for loading into a model in these locations:

  • MATLAB® (base) workspace, or function workspace

  • Model workspace

  • Function workspace

  • Masking workspace

  • Blocks

  • MAT-files

  • Spreadsheets

The MATLAB (base) workspace is the most common workspace to use for loading signal data.

MATLAB Workspace for Signal Data

Consider using the MATLAB (base) workspace when you want to:

  • Use a small amount of signal data for iterative simulations.

  • Use signal data logged during one simulation as input for another simulation.

  • Have multiple models use the same signal data.

Create Signal Data in the MATLAB Workspace

  • At the MATLAB command line or editor, create the signal data.

  • Use the xlsread function to read data from an Excel spreadsheet into the MATLAB workspace.

  • Use the readmatrix function to read data from a CSV spreadsheet into the MATLAB workspace.

  • Use a model callback to load signal data.

  • Use one of these Simulink logging techniques:

    • Signal logging

    • To Workspace block

    • Scope block

    • The Configuration Parameters > Data Import/Export pane, the Output, States, or Final states parameters

    • Data store

    • The sim command configured to log simulation data

Load Signal Data from the MATLAB Workspace.  To load signal data from a workspace, use one of these techniques:

  • Add a From Workspace block.

  • Use a root-level input port.

    • Specify workspace variables in the Configuration Parameters > Data Import/Export > Input parameter.

    • Use the Root Inport Mapper tool to specify the data for the Input parameter.

Source and Signal Editor Blocks for Signal Data

Source blocks, such as the Sine Wave block, generate signals that you can use as inputs to other blocks. Source blocks do not store signal data. Source blocks can be useful for initial prototyping of a model when the generated signal data serves your modeling requirements.

To define scenarios to use as inputs to a model, you can use the Signal Editor block. The Signal Editor block stores the scenario definitions.

Consider using a source block to:

  • Avoid having to create the data manually.

  • Reduce memory consumption — source blocks do not store signal data.

  • Graphically represent in the model the kind of signal data.

Consider using a Signal Editor block to:

  • Create and import scenarios for use in testing.

    You can use scenarios with Simulink and with these products:

    • Simulink Test™

    • Simulink Coverage™

    • Simulink Design Verifier™

  • Switch between scenarios quickly.

MAT-Files for Signal Data

Consider storing signal data in a MAT-file to:

  • Load a large amount of signal data efficiently.

  • Reuse the same signal data in different models.

  • Reduce memory requirements for the model.

  • Use different sets of signal data with the same model, with minimal model updates.

Store Signal Data in a MAT-File.  To create a MAT-file to store signal data to import, you can use:

  • A To File block

  • The Signal Editor user interface

  • MATLAB to create signal data that you store in a MAT-file

Load Signal Data from a MAT-File.  To load signal data from a MAT-file into a model, you can use a From File block.

Spreadsheets for Signal Data

Consider using an Excel or CSV spreadsheet to:

  • Use an existing spreadsheet that already has the necessary signal data or that you can update easily to contain the signal data.

  • Load a large amount of signal data efficiently.

  • Reduce memory requirements for the model.

  • Use different sets of signal data with the same model, with minimal model updates.

  • Share the signal data with other people who do not have Simulink installed.

Store Signal Data in a Spreadsheet.  Use one of these approaches:

  • Create the signal data directly in the spreadsheet.

  • Export MATLAB signal data to an Excel or CSV spreadsheet using the xlswrite or csvwrite function.

Load Signal Data from a Spreadsheet.  Use the From Spreadsheet.

The From Spreadsheet block loads Microsoft Excel on all platforms. This block loads CSV spreadsheets only on Microsoft Windows® platforms.

The From Spreadsheet block incrementally loads the data directly from the spreadsheet, to reduce memory consumption.

Load Input Signal Data

You can use various sources for input signal data for simulating a model. You can:

  • Use existing data from a file, such as a spreadsheet.

  • Write a MATLAB script to define variables for the signal data. For example, you can create Dataset format data that you can use with all the signal loading techniques.

  • Use data logged from a previous simulation.

You can use several different approaches to load data into a model, including:

  • Root-level input ports — Import signal data from a workspace, using the Input configuration parameter to import it to a root-level input port of a Inport, Enable, or Trigger block. You can specify the input data directly in the Input parameter. To import multiple signals to root-level input ports, consider using the Root Inport Mapping tool. That tool updates the Input parameter based on the signal data that you import and map to root-level input ports.

  • Source blocks — Add a source block, such Sine Wave block, to generate signals to input to another block.

  • From File block — Read data from a MAT-file, outputting the data as a signal.

  • From Spreadsheet block — Read data from Microsoft Excel spreadsheets or CSV spreadsheets, outputting the data as one or more signals.

To determine the approach to meet the input signal data requirements of your model, see Comparison of Signal Loading Techniques.

Log Output Signal Data

You can save signal values to the MATLAB workspace or to a MAT-file during simulation for later retrieval and postprocessing. Saving simulation data is also known as logging or exporting simulation data.

To determine which approach to use for logging signal data, see Save Simulation Data.

Saving simulation data in Dataset format simplifies postprocessing by providing a common format for the results of various logging techniques. Using Dataset format stores the data as MATLAB timeseriesobjects, which you can process with MATLAB. Simulink provides tools for converting data logged in other formats to Dataset format.

For more information about logging output signal data, see Save Run-Time Data from Simulation.

See Also


Related Topics