Main Content

mapDataToInport

Map data to root input ports

Since R2024b

    Description

    [inputSpec,output,validation] = mapDataToInport('Model',modelname,'DataSource',datasource) maps the contents of the datasource file to root input ports for modelname. The function returns the mapping results in inputSpec, output, and validation.

    [inputSpec,output,validation] = mapDataToInport(___,Name,Value) maps the contents of 'DataSource' with additional options specified by one or more name-value arguments.

    example

    Examples

    collapse all

    For the ex_root_inport_mapping_example.slx model, map the MAT file, ThreeMatlabTimeSeries.mat, to the input port using the mapping mode PortOrder. The file contains file type Simulink.io.MatFile data.

    Load the model, ex_three_inports.slx.

    load_system('ex_root_inport_mapping_example')

    Map data to inport.

    [inputSpec,output,validation ] = mapDataToInport('Model',...
    'ex_root_inport_mapping_example','DataSource',...
    'ThreeMatlabTimeSeries.mat','MappingMode',{'PortOrder' ''})
    The supported file type is Simulink.io.MatFile
    
    inputSpec = 
      InputSpecification with properties:
    
                      Mode: 'PortOrder'
         MappingDiagnostic: 'None'
                  InputMap: [1x3 Simulink.iospecification.InputMap]
            CustomSpecFile: []
        CustomSpecFilePath: []
                    Verify: 0
              AllowPartial: 0
    
    
    output = struct with fields:
        FileTypeUsed: 'Simulink.io.MatFile'
           Variables: {'var1'  'var2'  'var3'}
    
    
    validation = struct with fields:
        inportProps: {[]  []  []}
          dataProps: {[]  []  []}
           errorMsg: ''
        diagnostics: [1x3 struct]
    
    

    Get the information contained in the output structures.

    output.FileTypeUsed
    ans = 
    'Simulink.io.MatFile'
    
    output.Variables
    ans = 1x3 cell
        {'var1'}    {'var2'}    {'var3'}
    
    
    inputSpec.InputMap
    ans=1×3 InputMap array with properties:
        Type
        DataSourceName
        Destination
        Status
        BlockName
        BlockPath
        SignalName
        PortNumber
    
    
    inputSpec.InputString
    ans = 
    'var1,var2,var3'
    

    Input Arguments

    collapse all

    Model name, specified as a character vector or string.

    Example: 'Model','minportsOnlyModel'

    Data Types: char | string

    File name, specified as a character vector or string. The file can have any supported file type.

    Example: ThreeInportModelData.xlsx

    Data Types: char | string

    Name-Value Arguments

    Example: 'AllowPartialBusSpecification','false'

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Mapping mode, specified as one of these values:

    • 'BlockName'

    • 'BlockPath'

    • 'SignalName'

    • 'PortOrder'

    • 'Custom'

    For more information on mapping modes, see Choose Map Mode and Using Mapping Modes with Custom-Mapped External Inputs.

    Example: 'MappingMode','BlockName'

    Data Types: char | string

    Custom file type, specified as a character vector or string. The custom file type must be registered.

    Example: 'FileType',"Simulink.io.MatFile"

    Data Types: char | string

    Option to control compilation, specified as 1 (true) or 0 (false).

    Example: 'CompileIfNeeded','false'

    Data Types: char | string

    Option to control partial bus definition that allows partially specified bus data to map properly, specified as 1 (true) or 0 (false.

    Example: 'AllowPartialBusSpecification','false'

    Output Arguments

    collapse all

    Input specification of mapped data, returned as a structure with these fields:

    • InputMap — Mapping mode

    • InputString — Input string for simulation

    • Mode — Mapping status of each mapped input

    To access this information, use the format InputSpec.field. For example, to access the input string for simulation, use InputSpec.InputString.

    Output validation information, returned as a structure with these fields:

    • File type used — FileTypeUsed

    • Cell array of input variables or scenarios — Variables

    To extract this information, use the format output.field, for example, output.FileTypeUsed.

    Mapping status, returned as a structure containing validation information for the inputSpec. The fields include:

    • Data type, dimensions, and Inport blocks complexity — inportProps

    • Data type, dimensions, and complexity of data to be mapped to Inport blocks — dataProps

    • Errors returned during mapping — errorMsg

    To extract this information, use the format validation.field, for example, validation.inportProps.

    Version History

    Introduced in R2024b