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 signal data from channels to a multidimensional signal or from a multidimensional signal to channels.
Open and Simulate the Model
Open the model ConvertMultiDim
. Then, simulate the model.
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.
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.
Use the Children
property to access the Signal
object for each channel.
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.
The Run
object now contains only one signal with multidimensional sample values.
The Children
property of the top-level Signal
object now contains only one signal.
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.
ans = 101×3
1.1650 0 0
0.6268 0.0631 0.0998
0.0751 0.1265 0.1987
0.3516 0.1899 0.2955
-0.6965 0.2531 0.3894
1.6961 0.3157 0.4794
0.0591 0.3776 0.5646
1.7971 0.4383 0.6442
0.2641 0.4975 0.7174
0.8717 0.5550 0.7833
⋮
After conversion, the signal IDs for the Signal
objects that contained data for other channels become invalid.
Convert a Multidimensional Signal to Channels
Use the expand
function to convert the Mux output back to channels.
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.
ans = 101×1
1.1650
0.6268
0.0751
0.3516
-0.6965
1.6961
0.0591
1.7971
0.2641
0.8717
⋮
The Run
object and the Children
property of the top-level Signal
object both contain three signals.
Access the new Signal
object that contains the data for the second channel.