Main Content

expand

Represent multidimensional signal as group of signals with scalar sample values

    Description

    example

    expand(sigObj) converts the representation of the signal that corresponds to the Simulink.sdi.Signal object sigObj from a single signal with nonscalar sample values to a set of signals with scalar sample values: one signal, called a channel, for each element in the multidimensional sample values.

    Expanding a signal creates a new Signal object for each channel except the channel that corresponds to the first element in the multidimensional signal value. The data for the first channel in the multidimensional signal is stored in the Signal object that previously contained the multidimensional signal data.

    The expand function does not support variable-size signals.

    Examples

    collapse all

    When you analyze multidimensional signal data using the Simulation Data Inspector, you can choose whether to represent the data as a single signal with multidimensional sample values or as a set of signals, called channels, with scalar sample values. Use the Simulation Data Inspector programmatic interface to convert the representation of a signal created by logging the output of the Mux block in the model vdp.

    Open and Simulate the Model

    Open the model vdp, mark the output of the Mux block for logging, and name the Mux block otuput signal. Then, simultate the model.

    open_system('vdp');
    
    MuxPort = get_param('vdp/Mux','PortHandles');
    set_param(MuxPort.Outport,'DataLogging','on');
    
    MuxSig = get_param(MuxPort.Outport,'Line');
    set_param(MuxSig,'Name','Mux');
    
    sim('vdp');

    Access the Run and Signal Data

    By default, the output of the Mux block is represented as channels in the Simulation Data Inspector because it contains fewer than four channels, so the run contains two signals: one for each channel in the Mux block output.

    Use the Simulink.sdi.getCurrentSimulationRun function to access the Simulink.sdi.Run object that contains the simulation data. Then, check how many Simulink.sdi.Signal objects the Run object contains using the SignalCount property on the Run object.

    runObj = Simulink.sdi.getCurrentSimulationRun('vdp');
    runObj.SignalCount
    ans = int32
        2
    

    Signals with multidimensional data have a top-level Signal object that does not contain data. The Children property of the top-level signal object contains one or more Signal objects associated with the top-level composite signal that contain the data. Because the top-level signals do not contain data, they are not counted to determine the value of the SignalCount property for the Run object.

    Use the getSignalsByName function to access the top-level Signal object for the Mux block output.

    topSig = getSignalsByName(runObj,'Mux');

    Use the Children property to access the Signal object for each channel.

    sig1 = topSig.Children(1);
    sig1.Name
    ans = 
    'Mux(1)'
    
    sig2 = topSig.Children(2);
    sig2.Name
    ans = 
    'Mux(2)'
    

    Convert Channels to a Multidimensional Signal

    Use the collapse function to convert the representation of the Mux block output so you access the data as a single signal with multidimensional sample values.

    collapse(sig1)

    The Run object now contains only one signal with multidimensional sample values.

    runObj.SignalCount
    ans = int32
        1
    

    The Children property of the top-level Signal object now contains only one signal.

    size(topSig.Children)
    ans = 1×2
    
         1     1
    
    

    After you convert a signal from channels to multidimensional representation, the Signal object that previously contained the data for the first channel contains the data for the multidimensional signal.

    sig1.Values.Data
    ans = 64×2
    
        2.0000         0
        2.0000   -0.0002
        2.0000   -0.0012
        2.0000   -0.0062
        1.9998   -0.0306
        1.9943   -0.1398
        1.9379   -0.3840
        1.8155   -0.5570
        1.5990   -0.7204
        1.2687   -0.9452
          ⋮
    
    

    After conversion, the signal IDs for the Signal objects that contained data for other channels become invalid.

    isValidSignalID(runObj,sig2.ID)
    ans = logical
       0
    
    

    Convert a Multidimensional Signal to Channels

    Use the expand function to convert the Mux output back to channels.

    expand(sig1)

    After converting a multidimensional signal to channels, the Signal object that previously contained the data for the multidimensional signal contains the data for the first channel. New Signal objects are created for other channels.

    sig1.Name
    ans = 
    'Mux(1)'
    

    The Run object and the Children property of the top-level Signal object both contain two signals.

    runObj.SignalCount
    ans = int32
        2
    
    size(topSig.Children)
    ans = 1×2
    
         1     2
    
    

    Access the new Signal object that contains the data for the second channel.

    newSig = topSig.Children(2);
    newSig.Name
    ans = 
    'Mux(2)'
    

    Input Arguments

    collapse all

    Multidimensional signal to convert to channels, specified as a Simulink.sdi.Signal object. The expand function does not support variable-size signals.

    Introduced in R2021b