Main Content


Register adapter to convert test data

Since R2022b



sltest.testmanager.registerTestAdapter(adapterfcn,adapterdefault) registers an adapter function to convert an Excel® or MAT file that contains test data to a format supported by the Test Manager. For information about the supported Excel format, see Microsoft Excel Import, Export, and Logging Format.


collapse all

This example shows how to use and register a function that converts the formatting of an Excel spreadsheet so it can be used in the Test Manager. The spreadsheet has 6 sheets, each corresponding to an iteration. Each sheet has a header with the iteration name and description. The sheets also include the built-in formats for specifying test inputs, parameters, and baselines. This examples uses the CruiseContol model.

The files used in this example are:

  • CruiseControlTests_CustomHeader.xlsx - Excel spreadsheet

  • HybridBuiltInAdapter.m - Adapter function

  • CruiseControlTests_HybridBuiltInAdapter.mldatx - Test file

View the adapter function.

type HybridBuiltInAdapter.m
function HybridBuiltInAdapter(testCase, inputFileName)  

    % Find iteration test specs (worksheets)
    [sheets] = sheetnames(inputFileName); 

    % Configure test case from each worksheet
    for ii=1:numel(sheets)
        % Create new iteration object and get iteration information
        testItr = sltestiteration();
        [testItr.Name, testItr.Description,specRange] = ...
        % Add a single input set from worksheet and map to ports
        testInput = testCase.addInput(inputFileName,Sheet=sheets(ii),...

        % Add a single baseline set from worksheet
        baseline = testCase.addBaselineCriteria(inputFileName, ...
        % Add iteration to run in this test case

function [name,desc,specRange] = getTestInfo(inputFileName,sheetName)
% Get test name and description, input/output cell range, and 
% parameter data from worksheet
    rawT = readcell(inputFileName,'Sheet',sheetName,'UseExcel',false);

    % Assign missing data to '' for "isempty" checks
    rawT(cellfun(@(x) all(ismissing(x)), rawT)) = {''};

    % Find row with "Name" and find row with "Description"
    nameRow = find(cellfun(@(x) strcmpi(x,'Name'),rawT(:,1)),1);
    name = rawT{nameRow,2};
    descRow = find(cellfun(@(x) strcmpi(x,'Description'),rawT(:,1)),1);
    desc = rawT{descRow,2};

    % Find test vector row range
    timeRow = find(cellfun(@(x) strcmpi(x,'Time'), rawT(:,1)));
    endRow = numel(rawT(:,1));
    specRange = [num2str(timeRow) ':' num2str(endRow)];

Register the adapter.


Open the CruiseControlTests_HybridBuiltInAdapter test file in the Test Manager.

tf = sltest.testmanager.TestFile...

Selecting the Create Test Case from External File and specifying the File and Adapter in the Test Manager adds the data and information adapted from the Excel file. For example, see the Inputs and Iterations sections of the test case.

Test Manager section showing checkbox to create test case from external file and filled in file and adapter fields.

Input section showing the external inputs for each worksheet in the Excel file

Iterations showing the name and description for each iteration

Clean up and close the Test Manager.


Create and register a function to format a MAT file to use in the Test Manager. This example assumes that you have a MAT file that has x, y, and z parameters and xin and yin inputs.

Create a function that converts a baseline test parameter set in the MAT file.

function Adapter_InputBaselineParamSet(test,externalMATFile)
   % Set model property for the test case

   % Save external file parameters to a supported format
   % MAT file and add parameter set to test case
   paramset = addParameterSet(test,'FilePath',...

   % Save external file inputs to a supported format MAT
   % file and add inputs to test case
   inputs = addInput(test,'input.mat');;                         

   % Capture baseline criteria and add to test case

Then register the function by using its function handle.


Input Arguments

collapse all

Adapter function name, specified as a function handle. The adapter function specifies how to convert an Excel or MAT test data file into a format supported by the Test Manager.

Whether to use the specified adapter as the default for the test case, specified as a numeric or logical 1 (true) or 0 (false). When you set the adapterdefault input to 1 or true, the test case uses specified adapter even if you previously registered a different adapter.

Version History

Introduced in R2022b