Overview of Signal Loading Techniques
金宝app®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, seeComparison of Techniques.
Source Blocks
You can add a source block, such as aSine Waveblock, to generate signals to input to another block. To specify how to generate the signal, use the Block Parameters dialog box. For example, in theSine WaveBlock Parameters dialog box, you can specify thesim
function to use and time-based or sample-based data.
The output data types of source blocks vary. For example, aSine Waveblock outputs a vector of real doubles.
For an example of using a source block, seeBuild and Edit a Model Interactively.
Recommended Uses
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.
Limitations
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.
Root-Level Input Ports
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®(基地)、模型或面具工作区。这些块import data from the workspace based on the value of theConfiguration Parameters>Data Import/Export>Inputparameter or asim
command argument. For an example, seeLoad 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 theInputconfiguration parameter based on the signal data that you import and map to root-level input ports. For an example, seeMap Data Using Root Inport Mapper Tool.
Recommended Uses
Use root input ports to:
Import many signals to many blocks
测试你的模型作为参考模型在一个更广泛的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
Requirements
To ensure that the Simulink variable solver executes at the times that you specify in the imported data, set theConfiguration Parameters>
Data Import/Export>Additional parameters>
Output optionsparameter toProduce additional output
.
Limitations
You cannot use input ports to import buses in external modes. To import bus data in rapid accelerator mode, use
Dataset
format.The Root Inport Mapper tool supported map modes depend on the data type of a signal. For details, seeChoose a Base Workspace and MAT-File Format.
From File Block
AFrom Fileblock reads data from a MAT-file and outputs the data as a signal.
For an example, seeFrom File Block Loading Timeseries Data.
Recommended Uses
Consider using aFrom Fileblock for loading:
Large amounts of data. For a Version 7.3 MAT-file, theFrom Fileblock loads data incrementally from the MAT-file during simulation.
Tip
To convert a Version 7.0 file to Version 7.3 (for example,
my_data_file.mat
that contains the variablevar
), at the MATLAB command line, enter:load('my_data_file.mat') save('my_data_file.mat', 'var', '-v7.3')
Data that was exported to aTo Fileblock. TheFrom Fileblock reads data written by aTo Fileblock without any you modifying the data or making other special provisions.
Data stored in a MAT-file that is separate from the model file.
Limitations
ForVersion 7.0or earlier MAT-file, theFrom Fileblock reads only array-format data.
Version 7.3 and Version 7.0 or earlier MAT-files handle multiple variables differently. SeeMAT-File Variable.
TheFrom Fileblock supports reading nonvirtual bus signals in MATLAB
timeseries
format.For array data, theFrom Fileblock 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. SeeCode Generation.
From Spreadsheet Block
TheFrom Spreadsheetblock reads data fromMicrosoft®Excel®spreadsheets (all platforms) or CSV spreadsheets (Microsoft Windows®platform withMicrosoft Officeonly) and outputs the data as one or more signals.
Recommended Uses
Use theFrom Spreadsheetblock for loading:
LargeMicrosoft Excelor CSV spreadsheets. TheFrom Spreadsheetblock incrementally reads data from the spreadsheet during simulation, rather than loading the data into Simulink memory.
Spreadsheets that you expect to modify. TheFrom Spreadsheetblock handles changes to worksheet values automatically, because it loads data directly from the spreadsheet.
Limitations
You cannot import bus data.
The From Spreadsheet file has requirements for the spreadsheet data. Organize Excel spreadsheet data using the format described inSupported Microsoft Excel File Formats.
Linux®andMacplatforms do not support using a From Spreadsheet block to import data from a CSV spreadsheet.
From Workspace Block
TheFrom Workspaceblock reads signal data from a workspace and outputs the data as a signal. In the Block Parameters dialog box, in theDataparameter, enter a MATLAB expression that specifies the workspace data.
For an example of how to use a From Workspace block, seeUse From Workspace Block for Test Case.
Recommended Uses
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
Variable-size signals
Data that you saved using a To Workspace block in MATLAB
timeseries
format, without manual changes to the dataData saved in a previous simulation by aTo Workspaceblock in either
Timeseries
orStructure with Time
format for use in a later simulation
Limitations
The data expressions that you specify must evaluate to one of these types of data:
A
timeseries
ortimetable
objectA structure of
timeseries
ortimetable
objectsA structure, with or without time
A two-dimensional matrix
Signal Editor Block
Using aSignal Editorblock, you can create interchangeable scenarios to use in a model.
For examples of how to use aSignal Editorblock, see:
Recommended Uses
Use theSignal Editorblock to create and load scenarios to use in testing.
These products integrate theSignal Editorblock into their workflows:
Simulink Test™
Simulink Coverage™
Simulink Design Verifier™
Limitations
Function-calls
Array of buses
Buses while using rapid accelerator mode
timetable
objectsGround signals
TheSignal Editorblock supports dynamic strings. It does not support strings with maximum length. In addition, strings in theSignal Editorblock cannot output:
Non-scalar MATLAB strings.
String data that contains missing values.
String data that contains non-ASCII characters.
Related Examples
- Load Data to Root-Level Input Ports
- Map Data Using Root Inport Mapper Tool
- Load Data Using the From File Block
- Load Data Using the From Workspace Block
- Load Signal Data That Uses Units