주요 콘텐츠

addMapping

Add new mapping entries to adapter

Since R2026a

    Description

    addMapping(adapter,inputElements,outputElements) adds new mapping entries to the adapter specified by adapter based on the equal-sized arrays of input elements in inputElements and output elements in outputElements.

    example

    Examples

    collapse all

    Create and connect an adapter to three components in System Composer™. Then, add mapping.

    Create a model and get the root architecture.

    model = systemcomposer.createModel("archModel");
    systemcomposer.openModel("archModel");
    rootArch = get(model,"Architecture");

    Create three new components.

    names = ["Component1","Component2","Component3"];
    newComponents = addComponent(rootArch,names);

    Add ports to the components.

    comp1 = getComponent(rootArch,"Component1");
    comp2 = getComponent(rootArch,"Component2");
    comp3 = getComponent(rootArch,"Component3");
    outPort1 = addPort(comp1.Architecture,"p1","out");
    outPort2 = addPort(comp2.Architecture,"p2","out");
    inPort1 = addPort(comp3.Architecture,"p3","in");

    Extract the component ports.

    srcPort1 = getPort(comp1,"p1");
    srcPort2 = getPort(comp2,"p2");
    destPort = getPort(comp3,"p3");

    Create an adapter.

    adapter = rootArch.addAdapter(InputName=["p1","p2"],OutputName=["p3"]);

    Connect the adapter to the three components.

    adapter.connectTo(SourcePort=[srcPort1,srcPort2],TargetPort=[destPort]);

    Improve the model layout.

    Simulink.BlockDiagram.arrangeSystem("archModel")

    Create two interfaces with two elements each.

    interface1 = addInterface(model.InterfaceDictionary,"newInterface1");
    element1a = addElement(interface1,"elem1a",DataType="double");
    element1b = addElement(interface1,"elem1b",DataType="double");
    
    interface2 = addInterface(model.InterfaceDictionary,"newInterface2");
    element2a = addElement(interface2,"elem2a",DataType="double");
    element2b = addElement(interface2,"elem2b",DataType="double");

    Assign the interfaces to ports.

    srcPort1.setInterface(interface1);
    destPort.setInterface(interface2);

    Remove default mapping in the adapter.

    adapter.removeMapping("p1");

    Add mapping through the adapter.

    adapter.addMapping(["p1.elem1a","p1.elem1b"],["p3.elem2a","p3.elem2b"]);

    Input Arguments

    collapse all

    Adapter, specified as a systemcomposer.arch.Adapter object.

    Qualified input port element names to map from, specified as a string or array of strings.

    The number of elements in inputElements must match the number of elements in outputElements.

    Example: adapter.addMapping(["p1.elem1","p1.elem2"],["p3.e1","p3.e2"])

    Data Types: string

    Qualified output port element names to map to, specified as a string or array of strings.

    The number of elements in inputElements must match the number of elements in outputElements.

    Example: adapter.addMapping(["p1.elem1","p1.elem2"],["p3.e1","p3.e2"])

    Data Types: string

    More About

    collapse all

    Version History

    Introduced in R2026a