addInput
Class: sltest.testmanager.TestCase
Namespace: sltest.testmanager
Add input file to test case
Description
adds a file to the Inputs section of the test case and returns a
test input object, input
= addInput(tc
,file
,Name,Value
)sltest.testmanager.TestInput
.
Input Arguments
tc
— Test case
sltest.testmanager.TestCase
object
Test case that you want to add the test input to, specified
as a sltest.testmanager.TestCase
object.
file
— Input filename and path
character vector
Name and path of MAT-file or Microsoft® Excel® input file, specified as a character vector.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'Sheets','mysheet','Ranges','C1:F10','CreateIterations',false
SimulationIndex
— Test case simulation number
1 | 2
Test case simulation number that the inputs
apply to, specified as 1
or
2
. This setting applies to
equivalence tests.
Example: 'SimulationIndex',2
CreateIterations
— Create a table iteration from the input
true (default) | false
Option to add the input file to the iteration table under Iterations in the test case, specified as Boolean.
Example: 'CreateIterations',false
Sheets
— Names of sheets to use as inputs
character vector | string | array of strings
Names of sheets from Excel file to use as test case inputs, specified as a character vector, string, or array of strings.
Example: 'testinputs'
,
["Heater","Plant"]
Ranges
— Range of cells from sheet
character vector | string | array of strings
Ranges of cells from the sheets that you
added as inputs, specified as a character vector, string, or array of strings.
You can specify 'Ranges'
only if you also specify
'Sheets'
. The ranges you specify must correspond to the
sheets. For example, if you specify one sheet, specify one range. If you
specify a cell array of sheets, each value in the 'Ranges'
cell array must correspond with a sheet in the 'Sheets'
cell
array.
You can specify 'Ranges'
as shown in the table.
Ways to specify Range
| Description |
---|---|
Rectangular Range |
Specify the range using the syntax
Example:
|
Unspecified or Empty | If unspecified, the importing function automatically detects the used range. Example:
Note: Used Range refers to the rectangular portion of the spreadsheet that actually contains data. The importing function automatically detects the used range by trimming leading and trailing rows and columns that do not contain data. Text that is only white space is considered data and is captured within the used range. |
Row Range | You can identify the range by specifying the beginning
and ending rows using Excel row designators. Then Example:
|
Column Range | You can identify the range by specifying the beginning
and ending columns using Excel column designators. Then
Example:
|
Excel Named Range |
In Excel, you can create names to identify ranges in the
spreadsheet. For instance, you can select a rectangular portion
of the spreadsheet and call it Example:
|
Example: 'B2:C30'
,
"D2:E30"
, ["B2:C30", "D2:E30",
"B2:C30"]
SeparateInputs
— Specify separate inputs
true (default) | false
Option to use each sheet in the Excel file or specified by the
'Sheets'
argument as a separate input, specified as
true
or false
.
Output Arguments
input
— Test input
sltest.testmanager.TestInput
object | array of sltest.testmanager.TestInput
objects
Test input, returned as an sltest.testmanager.TestInput
object
or an array of sltest.testmanager.TestInput
objects.
Examples
Add Microsoft® Excel® Data as Input
This example shows how to add data from a Microsoft® Excel® spreadsheet and map it to a test case. Only the two sheets that have data are added and mapped.
Load the Example Model
open_system('slexAutotransRootInportsExample');
Create a New Test File
tf = sltest.testmanager.TestFile('input_test_file.mldatx');
Get the Test Suite and Test Case Objects
ts = getTestSuites(tf); tc = getTestCases(ts);
Add the Example Model as the System Under Test
setProperty(tc,'Model','slexAutotransRootInportsExample');
Add Excel® Data to Inputs Section and Specify Sheets to Add
excelfile = 'sltestExampleInputs.xlsx'; input = addInput(tc,excelfile,'Sheets',["Acceleration","Braking"]);
Use Default Mapping Mode to Map the Input Signals for the Sheets
map(input(1)); map(input(2));
Specify Sheets and Ranges for Microsoft Excel File
This example shows the syntax to add Excel file sheets and range.
% Create test file tf = sltest.testmanager.TestFile('Excel Input Test File'); % Create test suite and test case ts = createTestSuite(tf,'Excel Test Suite'); tc = createTestCase(ts,'baseline','Excel Input Test Case'); % Add Excel data to Inputs section, specifying sheets and range input = addInput(tc,'C:\MyHomeDir\myexcel.xlsx',... 'Sheets',["Optics","Torque","Throttle"],... 'Ranges',["B1:C20","","D1:G10"]);
Version History
Introduced in R2015b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)