Simulink® provides several techniques for importing signal data into a model. Each of the signal data loading techniques uses blocks to represent signal data sources visually.
For additional details about which technique to use to meet specific modeling requirements, see Comparison of Techniques.
You can add a source block, such as a Sine Wave block, to generate
signals to input to another block. To specify how to generate the signal, use the Block
Parameters dialog box. For example, in the Sine Wave Block Parameters dialog
box, you can specify the
sim function to use and time-based or
The output data types of source blocks vary. For example, a Sine Wave block outputs a vector of real doubles.
For an example of using a source block, see Build and Edit a Model Interactively.
Do initial prototyping in a model, when the generated signal data serves your modeling requirements
Avoid creating the data manually.
Reduce memory consumption. Source blocks do not store signal data.
Make the kind of signal data visually clear in the model.
Source blocks generate signals based on a predefined algorithm. To use actual data from an external source or to test a model without having to modify the model, use a different signal loading technique.
You can import signal data from a workspace and apply it to a root-level input port using one of these blocks:
The root-level input ports load external inputs from the MATLAB® (base), model, or mask workspace. These blocks import data from the workspace
based on the value of the Configuration Parameters > Data Import/Export > Input parameter or a
sim command argument. For an example, see
Load Data to Model a Continuous Plant.
To import many signals to root-level input ports, consider using the Root Inport Mapper tool. This tool updates the Input configuration parameter based on the signal data that you import and map to root-level input ports. For an example, see Map Data Using Root Inport Mapper Tool.
Use root input ports to:
Import many signals to many blocks
Test your model as a referenced model in a wider context with signals from the workspace, without modifying your model
For importing signal data to meet most modeling requirements and to maintain model flexibility, root-level inport mapping is a convenient technique. Root-level inport mapping:
Displays signal data for you to inspect without loading all the signal data into MATLAB memory
Provides memory-efficient signal viewing
To ensure that the Simulink variable solver executes at the times that you specify in the imported data,
set the Configuration Parameters >
Data Import/Export > Additional parameters >
Output options parameter to
Produce additional output.
You cannot use input ports to import buses in external modes. To import bus data
in rapid accelerator mode, use
The Root Inport Mapper tool supported map modes depend on the data type of a signal. For details, see Choose a Base Workspace and MAT-File Format.
A From File block reads data from a MAT-file and outputs the data as a signal.
For an example, see From File Block Loading Timeseries Data.
Consider using a From File block for loading:
Large amounts of data. For a Version 7.3 MAT-file, the From File block loads data incrementally from the MAT-file during simulation.
To convert a Version 7.0 file to Version 7.3 (for example,
my_data_file.mat that contains the variable
var), at the MATLAB command line, enter:
load('my_data_file.mat') save('my_data_file.mat', 'var', '-v7.3')
Data that was exported to a To File block. The From File block reads data written by a To File block without any you modifying the data or making other special provisions.
Data stored in a MAT-file that is separate from the model file.
For Version 7.0 or earlier MAT-file, the From File block reads only array-format data.
Version 7.3 and Version 7.0 or earlier MAT-files handle multiple variables differently. See MAT-File Variable.
The From File block supports reading nonvirtual bus signals in
For array data, the From File block reads only double signal data.
Code generation that involves building ERT or GRT targets, or using SIL or PIL simulation modes, has some special considerations. See Code Generation.
The From Spreadsheet block reads data from Microsoft® Excel® spreadsheets (all platforms) or CSV spreadsheets (Microsoft Windows® platform with Microsoft Office only) and outputs the data as one or more signals.
Use the From Spreadsheet block for loading:
Large Microsoft Excel or CSV spreadsheets. The From Spreadsheet block incrementally reads data from the spreadsheet during simulation, rather than loading the data into Simulink memory.
Spreadsheets that you expect to modify. The From Spreadsheet block handles changes to worksheet values automatically, because it loads data directly from the spreadsheet.
You cannot import bus data.
The From Spreadsheet file has requirements for the spreadsheet data. Organize Excel spreadsheet data using the format described in Supported Microsoft Excel File Formats.
Linux® and Mac platforms do not support using a From Spreadsheet block to import data from a CSV spreadsheet.
The From Workspace block reads signal data from a workspace and outputs the data as a signal. In the Block Parameters dialog box, in the Data parameter, enter a MATLAB expression that specifies the workspace data.
For an example of how to use a From Workspace block, see Use From Workspace Block for Test Case.
Use the From Workspace block for loading:
A small set of signal data to perform local, temporary testing
Data from the MATLAB (base), model, mask, or function workspace
Data that you saved using a To Workspace block in MATLAB
timeseries format, without manual changes to the data
Data saved in a previous simulation by a To Workspace block in either
Structure with Time format for use in a later
The data expressions that you specify must evaluate to one of these types of data:
Using a Signal Editor block, you can create interchangeable scenarios to use in a model.
For examples of how to use a Signal Editor block, see:
Use the Signal Editor block to create and load scenarios to use in testing.
These products integrate the Signal Editor block into their workflows:
Simulink Design Verifier™
Array of buses
Buses while using rapid accelerator mode
The Signal Editor block supports dynamic strings. It does not support strings with maximum length. In addition, strings in the Signal Editor block cannot output:
Non-scalar MATLAB strings.
String data that contains missing values.
String data that contains non-ASCII characters.