Why are 2-D scalar signals being logged as 1x1xN while 1-D scalar signals logged as Nx1 in Simulink and how can I switch between them?

19 views (last 30 days)
In the attached model "untitled.slx" (screenshot is also provided below), a constant block outputs a signal of dimensions [1x2] to a gain block that does matrix multiplication with a gain parameter of dimensions [2x1].  This yields an output with dimensions [1x1].  The scope data is logged as the variable "ScopeData" in format "Structure With Time".  After running the simulation, the logged signal from the output of the Gain block (the first row of "ScopeData.signals") has dimensions 1x1xN, instead of Nx1, where in this model N = 11 refers to the number of time points.
The questions:
1) How can I have the output of the Sum block logged as Nx1 instead of 1x1xN?
2) What is the difference between the signal dimensions of 2-D scalars (dimensions [1x1]) and 1-D scalars (dimensions [1])
3) Why the signals are logged as 1x1xN instead of Nx1?
4) Why is "Display > Signal & Ports > Signal Dimensions" unable to show any distinction between 2-D scalars and 1-D scalars?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Apr 2023
Edited: MathWorks Support Team on 14 Apr 2023
1) Insert a "Reshape" block at the output of the Gain block, set the "Output dimensionality" to "Customize", and set the "Output dimensions" to [1]
2) The distinction is related to 1-D vectors with one element vs. matrices of size 1x1, and the distinction is maintained for compatibility reasons.  An example scenario in which this occurs is when matrix multiplication mode is used, which leads to the output of a matrix with [1x1] dimensions.  The workaround is to use the Reshape block to specify the output dimensions appropriately.
3) This comes back to the aspect that the signal is treated as a 2-D scalar at each time step, instead of a 1-D scalar.  Simulink treats these two types of scalars as distinct.  Consequently, as per the
, the logged signals are then 3-D arrays instead of 2-D arrays.
4) This is a known limitation, and a section of
addresses this and specifically mentions, "Simulink does not display any size information for a 1-D or 2-D scalar signal".  The "Check Signal Attributes" block can be used to distinguish between the two.  However, the "Display > Signal & Ports > Signal Dimensions" menu option does not display size information for a 1-D or 2-D scalar signal, as per the documentation page whose link is given above.

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!