Main Content

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 map modes indicated in Choose Map Mode.

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. For more information on map modes, see 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.

See Also

Related Topics