以下介绍两种方法
1.从workspace 2.从signal bulider
| On this page… |
| Guidelines for Importing a Test Case Example of Test Case Data Using a From Workspace Block to Import an Input Test Case Using a Signal Builder Block to Import an Input 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.
使simulink在非连续点求解。
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.
Using a From Workspace Block to Import an Input Test Case
1.Open the ex_data_import_test_case_from_workspace.mdl model.
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.
Using a 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_builder model.
2.Create a structure and save it in a MAT-file:
3.var.time = [0 1 1 5 5 8 8 10];
4.var.signals.values = [0 0 2 2 2 3 3 3]';
5.var.signals.dimensions = 1;
6.var.signals.label = 'var';
7.save var.mat var
8.Double-click the Signal Builder block to open its dialog box.
9.Select File>Import From File menu item, and select the var.mat file.
10.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 Importing Data from a Microsoft Excel Spreadsheet.
从Microsoft Excel表格导入数据
用Signal Builder作为输入源,并为其导入信号数据。
mporting Data from a Microsoft Excel Spreadsheet
You can use a Signal Builder block as the input source for your model and to import your own signal data to the model.
1.Start the MATLAB software. If you need instructions, consult your MATLAB documentation.
2.At the MATLAB command line, enter sldemo_2counters. This command starts the Simulink software and opens the model.
3.In the model window, double-click the Signal Builder block. The Signal Builder window opens and displays one data group with a default signal.
Copy以复制测试图形
从文件导入
Prepare for importing a Microsoft Excel spreadsheet that contains data on two sheets by creating a second group. Each sheet of data requires its own group. From the menu bar, select Group>Copy. A second tab, Group 2, appears.
Import the data by selecting File>Import from File. An Import File dialog box opens.
Use the Browse button to open the sldemo_signal_builder.xls file.
Under Data to Import , select the Select All check box.
Under Placement for Selected Data, select Append selected signals to different groups. This option causes the Signal Builder to convert the data on each sheet into a group and to enable the Validate Selection button.
Click the Validate Selection button.
Review the Status History pane.
Excel数据格式如下
The history indicates the following information:
∙The data importation is successful.
∙The Signal Builder block recognizes one signal per sheet.
∙The Signal Builder block recognizes the signal name, Amplitude, from the Excel® spreadsheet.
Click OK. The window closes.
In the Signal Builder window, delete the red default signal from Group 1 by clicking it and then pressing the Delete button on your keyboard. The signal is automatically deleted from Group 2 as well.
From the Signal Builder menu bar, select Axes>Set T Display Limits. A dialog box opens. Set the maximum time limit to 2.0.
Save your Signal Builder data to the model. In the Signal Builder window, select File>Save.
Your signal groups appear as shown. Keep this window open.
设置时间轴的显示范围
Axes>Set T Display Limits.
设置模型
For Logging Output Signals
To log and display your output, you must configure the data import and export parameters of the model.
1.In the model window, select Simulation>Configuration Parameters. The Configuration Parameters dialog box opens to the Solver pane.
2.Navigate to the Data Import/Export pane by clicking its title in the tree.
3.Select the following check boxes:
∙Time
∙Output
∙Signal logging
∙Record and inspect simulation output
4.Change Format from Array to Structure with time.下载本文