Main Content

addInput

Class: sltest.testmanager.TestCase
Namespace: sltest.testmanager

Add input file to test case

Description

input = addInput(tc,file,Name,Value) adds a file to the Inputs section of the test case and returns a test input object, sltest.testmanager.TestInput.

example

Input Arguments

expand all

Test case that you want to add the test input to, specified as a sltest.testmanager.TestCase object.

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

Pairs for MAT-Files and Microsoft Excel Files

expand all

Test case simulation number that the inputs apply to, specified as 1 or 2. This setting applies to equivalence tests.

Example: 'SimulationIndex',2

Option to add the input file to the iteration table under Iterations in the test case, specified as Boolean.

Example: 'CreateIterations',false

Pairs to Use Only with Microsoft Excel Files

expand all

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 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

'Corner1:Corner2'

Rectangular Range

Specify the range using the syntax 'Corner1:Corner2', where Corner1 and Corner2 are two opposing corners that define the region. For example, 'D2:H4' represents the 3-by-5 rectangular region between the two corners D2 and H4 on the worksheet. The 'Range' name-value pair argument is not case-sensitive, and uses Excel A1 reference style (see Excel help).

Example: 'Range','Corner1:Corner2'

''

Unspecified or Empty

If unspecified, the importing function automatically detects the used range.

Example: 'Range',''

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.

'Row1:Row2'

Row Range

You can identify the range by specifying the beginning and ending rows using Excel row designators. Then readtable automatically detects the used column range within the designated rows. For instance, the importing function interprets the range specification '1:7' as an instruction to read all columns in the used range in rows 1 through 7 (inclusive).

Example: 'Range','1:7'

'Column1:Column2'

Column Range

You can identify the range by specifying the beginning and ending columns using Excel column designators. Then readtable automatically detects the used row range within the designated columns. For instance, the importing function interprets the range specification 'A:F' as an instruction to read all rows in the used range in columns A through F (inclusive).

Example: 'Range','A:F'

'NamedRange'

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 'myTable'. If such named ranges exist in a spreadsheet, then the importing function can read that range using its name.

Example: 'Range','myTable'

Example: 'B2:C30', "D2:E30", ["B2:C30", "D2:E30", "B2:C30"]

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

expand all

Test input, returned as an sltest.testmanager.TestInput object or an array of sltest.testmanager.TestInput objects.

Examples

expand all

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));

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