How can I use a subsystem reference mask to find the dimensions of an input signal in Simulink R2024a?

조회 수: 1 (최근 30일)
In my Simulink R2024a model, I have a "Subsystem Reference" block that accepts an input signal. I would like to use the mask parameters on this block to find the dimensions of the input signal, instead of using extra blocks such as a "Width" block. How can I achieve this workflow?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 9월 16일
As of MATLAB R2024a, this workflow is not supported. To find the dimensions of a port signal, you may use the "CompiledPortDimensions" block parameter. However, since masks are evaluated during model compilation, this block parameter will not be available upon calling "get_param". Please refer to the documentation page Determine Signal Dimensions for more information about "CompiledPortDimensions".
As a workaround, you can use the "StartFcn" block callback instead of a mask, which runs after a model is compiled and before it starts running. To do so, please follow these steps:
  1. In the relevant "Subsystem Reference" block, create a mask with a dialog parameter with the name "<variable>" by following the steps in the documentation page Create a Simple Mask.
  2. Right click on the "Subsystem Reference" block and select "Properties" in the drop-down menu.
  3. Navigate to the "Callbacks" tab and select the "StartFcn" option in the callback list.
  4. In the code area, enter the following code:
    portHandles = get_param(gcb, PortHandles);
    portDims = get_param(portHandles.Inport, CompiledPortDimensions);
    set_param(gcb, <variable>, num2str(portDims(<dimension>)));
    Where <dimension> is an integer with a value of 1 greater than the dimension requested of the input signal. The first element of "CompiledPortDimensions" is the always the size of the resulting array.
For more information about the "StartFcn" callback and block parameters, please refer to the documentation pages Block Callbacks and Set Block Parameter Values, respectively.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by