Simulink mask: show/hide the port of a custom Simulink block

조회 수: 58 (최근 30일)
federico ciresola
federico ciresola 2024년 8월 2일
편집: Aurélien 2025년 8월 1일
Hi guys,
I am creating a mask for my custom block and I want add a checkbox with the following behaviour:
  • checked: it shows a new port the the block
  • unhecked: it hides the new port for the block
The integrator block has the same behaviour (see the belows images to understand):
I am struggling how to implement this feature in the Checkbox callback because I can't find the parameter to show/hide the port.

답변 (2개)

SACHIN KHANDELWAL
SACHIN KHANDELWAL 2024년 8월 2일
I understand that you want to create a block mask with the help of a checkbox. Here are some possible steps that might be helpful to you:
  1. Open Simulink and add a Subsystem block.
  2. Select Mask > Create Mask.
  3. Add a Checkbox and other properties that you want.
  4. Add the callback for the Checkbox.
After creating the callbacks, you can simply get the current callbacks using the following command:
>> maskObj = Simulink.Mask.get(gcb);
After you have the mask object, you can modify it based on your needs.
The following documentation could be helpful for you to design the mask:
Hope the above information is helpful!
  댓글 수: 1
federico ciresola
federico ciresola 2024년 8월 2일
편집: federico ciresola 2024년 8월 2일
thank you for you answer, I alread have did them. My problem is find a way to show or hide some inputs port from a checkbox such as the integrator block.

댓글을 달려면 로그인하십시오.


Aurélien
Aurélien 2025년 7월 31일
편집: Aurélien 2025년 8월 1일
Here is an example of how to re-create the Integrator block behavior on a Mask. The initial condition parameter value is used in a Constant block inside the masked subsystem.
It's important to use the initialization() function instead of a callback and to check the box below:
So you can create a custom library of your block without links issues.
If you want to give a name to that Constant block, replace all three gcb with gcb + "/block_custom_name" in the code below:
% Initialization code section
function initialization()
checkboxValue = get_param(gcbh, 'checkbox');
maskObj = Simulink.Mask.get(gcbh);
initParam = maskObj.getParameter('initial_condition_parameter');
if checkboxValue == "on"
% Replace constant block with inport block
replace_block(gcb, "Constant", "Inport", "noprompt");
initParam.Visible = "off"; % Hide parameter
else
% Replace inport block with constant block
replace_block(gcb, "Inport", "Constant", "noprompt");
set_param(gcb, "Value", "initial_condition_parameter", ...
"SampleTime", "-1"); % Give block properties back
initParam.Visible = "on"; % Show parameter
end
end
% Parameter callback section
Hope it helps :)

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by