Create Signal Data for Root Inport Mapping

The first step for using the Root Inport Mapper tool is to know the source of signal data to import and map. You can use existing data (for example, in a Microsoft® Excel® spreadsheet), create data in a MAT-file, or use the Signal Editor interface to create signal data.

For a summary of the other steps involved in using the Root Inport Mapper tool, see Import and Mapping Workflow.

Choose a Source for Data to Import and Map

You can import data from these sources.

  • Base workspace — You can selectively import data from the base workspace. For more information about supported data formats, see Choose a Base Workspace and MAT-File Format.

  • Data files — You can selectively import signals contained in MAT-files and Microsoft Excel files. Each time that you import the contents of the file, the contents overwrite data already loaded for the file in the Root Inport Mapper tool.

    For more information, see Choose a Base Workspace and MAT-File Format and Supported Microsoft Excel File Formats.

    Tip

    To load input data for a simulation from a Microsoft Excel spreadsheet, consider using the From Spreadsheet block. The From Spreadsheet block incrementally loads data from the spreadsheet during simulation. If you use a From Spreadsheet block, you do not need to do anything to handle changes to sheet values.

You can also use the Signal Editor interface to create and edit signal data. For more information, see Create and Edit Signal Data.

Choose a Naming Convention for Signals and Buses

When identifying signals to import, consider using a naming convention for signals and buses such that this grouping of data (scenario) is interchangeable. For example, you can have two MAT-files with the same set of variables named with the naming convention but different data values. Then, you can switch the scenarios of input data into and out of a model easily.

Choose a Base Workspace and MAT-File Format

The Root Inport Mapper tool supports the MATLAB® data types or formats described in the table for imported signal data. For each data type, you can use the mapping modes indicated in the table.

Data FormatsBlock NameBlock PathSignal NamePort OrderCustom

Simulink.SimulationData.Dataset

MATLAB timeseries

 

MATLAB timetable

 

Simulink.SimulationData.Signal

Stateflow.SimulationData.State

Structure with time and structure without time

    

Data array

    

Array of buses

 

Asynchronous function-call signal

 

Note

If your MAT-file or base workspace contains data in a format that the Root Inport Mapper tool does not support, the tool ignores that data.

Note

Although the Root Inport Mapper tool accepts these formats, it can only link in a Simulink.SimulationData.Dataset object. To convert the data in your MAT-file to a Simulink.SimulationData.Dataset object, in the Root Inport Mapper From dialog box, select the Convert signals into a scenario dataset and save to MAT-file check box. Alternatively, use the convertToSLDataset function to convert your data.

Note

When you specify a timetable as an element in the Dataset or a bus, the timetable must contain data for only one signal.

Dataset Signal Data

If data sets have nonunique element names, use the Port Order map mode.

MATLAB Timeseries Signal Data

If you have MATLAB timeseries data that includes enumeration data, and the enumeration class is not on your MATLAB path, the tool ignores that timeseries data.

Structure Signal Data

When converting structure signal data to datasets, the signals are named using the value contained in the label field of the signal field of the structure signal.

Array Signal Data

The Root Inport Mapper tool tries to map the data array to a single input port. In this case, you can choose any of the map modes.

Bus Signal Data for Root Inport Mapping

The signal data that you import and map to a root-level Inport block can include bus data. You cannot map bus signals to a root-level Enable or Trigger block.

  1. In the MATLAB workspace, create or load a bus object for the bus data you want to import and map.

  2. If you create a bus object in the base workspace, save the bus object definition to a MAT-file, such as d_myBusObj.mat.

  3. Create a separate MAT-file that contains the bus data you want to import for the bus object. Use one of these approaches:

    • Use an existing MAT-file that already contains a MATLAB struct or Simulink.SimulationData.Dataset object.

    • Create the bus in the base workspace and then save it to a MAT-file.

  4. Set up the model to load the bus object.

    • For root-level Inport blocks that you map signals to, set the Data type field to Bus. Specify the name of the variable for the bus object to be used for signal mapping.

    • Load into the model the MAT-file that includes the bus objects used for mapping. For example, use a PreLoadFcn callback function. For details, see Alternative Workflows to Load Mapping Data.

Create Signal Data in a MAT-File for Root Inport Mapping

You can create signal data in a MAT-file to use for root-inport mapping. For example, you can import three signals (signal1, signal2, and signal3) and save the signals in a MAT-file. The Simulink.SimulationData.Signal objects include signal names, block names, block paths, and port order index values.

You can use the convertToSLDataset function to convert MAT-file contents to Simulink.SimulationData.Dataset objects.

  1. In MATLAB, create three Simulink.SimulationData.Signal objects, specifying signal names, block paths, and port order index values.

    signal1 = Simulink.SimulationData.Signal;
    signal1.Name = 'signal1';
    signal1.BlockPath = Simulink.SimulationData.BlockPath('Out1');
    signal1.PortType = 'inport';
    signal1.PortIndex = 1;
    
    signal2 = Simulink.SimulationData.Signal;
    signal2.Name = 'signal2';
    signal2.BlockPath = Simulink.SimulationData.BlockPath('Out2');
    signal2.PortType = 'inport';
    signal2.PortIndex = 2;
    
    signal3 = Simulink.SimulationData.Signal;
    signal3.Name = 'signal3';
    signal3.BlockPath = Simulink.SimulationData.BlockPath('Out3');
    signal3.PortType = 'inport';
    signal3.PortIndex = 3;
    
  2. In the MATLAB workspace, select signal1, signal2, and signal3. Right-click the selection, and in the context menu, click Save as. Save the file as mySigData.mat.

  3. Open the MAT-file.

    open mySigData.mat
    ans = 
    
        signal1: [1x1 Simulink.SimulationData.Signal]
        signal2: [1x1 Simulink.SimulationData.Signal]
        signal3: [1x1 Simulink.SimulationData.Signal]

You can use the Signal Name, Block Name, Block Path, or Port Order map mode with this MAT-file. Based on your map mode, the Root Inport Mapper tool maps the signal data from the MAT-file to corresponding ports.

Supported Microsoft Excel File Formats

You can use the Root Inport Mapper tool to import data from Excel spreadsheets. You can also use the Root Inport Mapper tool to import signal data in CSV files on a Windows® system with Microsoft Office installed. The Root Inport Mapper tool does not support Excel spreadsheet charts.

  • Use sheet names that follow MATLAB variable name rules. If you import from a sheet whose name does not follow these rules, the Root Inport Mapper tool uses a modified sheet name. This modified sheet name follows the MATLAB variable name rules. For example, if you have a sheet name Group Name, the Root Inport Mapper uses the modified name GroupName.

  • Use the first row of a sheet to specify signal names. Either specify a signal name for every signal or do not specify any signal names. If you do not specify any signal names, the tool assigns signal names using the format Signal#.

  • For time values, use the first column of the remaining rows. The time values must increase for each row.

  • Put signal values in the remaining columns.

  • During import, the Root Inport Mapper tool converts formatted numbers from Excel spreadsheets to doubles.

  • The Root Inport Mapper tool does not support block path mapping mode for spreadsheets.

This example of a Microsoft Excel spreadsheet is set up for root-inport mapping.

  • The sheet name is sigData, which is a valid MATLAB variable name.

  • The first row contains the signal names signal1, signal2, and signal3.

  • The first column has six time values that increase for each row.

  • In each row with a time value, columns to the right of the first column contain signal data values for each signal.

Related Examples

More About