Dynamic mask creation - input values

1 view (last 30 days)
João Araújo
João Araújo on 10 Jun 2022
Answered: T.Nikhil kumar on 23 Oct 2023
Hello, I am trying to create a mask where it could take the input from a port or from a dialog and allow to select it. I tried the mask initialization code but couldn't get it to change anything:
freqsw = get_param(gcb,'inputopt');
switch freqsw
case 'Input Port'
replace_block([gcb '/Constant5'],'built-in/Constant','built-in/InPort','noprompt');
case 'Dialog'
replace_block([gcb '/Constant5'],'built-in/InPort','built-in/Constant','noprompt');
end
Can you point me to any examples or give any hints on how to do this?
Thank you

Answers (1)

T.Nikhil kumar
T.Nikhil kumar on 23 Oct 2023
Hello João Araújo,
As per my understanding, you want to create a mask for a block with a parameter that can have ‘Input Port’ or ‘Dialog’ as its value and based on this value, you want to execute a code snippet.
You can use the Simulink Mask Editor to create the required mask for your block. Please follow the below mentioned steps to achieve the goal:
  • Right-click on the block and select "Create Mask" in the ‘Mask’ section to open the Mask Editor.
  • In this Mask Editor, open the "Parameters & Dialog". Drag a “popup” type field from the left side ‘parameter’ gallery and drop into the "Parameters & Dialog" tab. Set the “prompt” field to a meaningful name like “Frequency Switch”.
  • You can then specify a list of options in the "Type Options" property in separate lines, for example 'Input Port’ ;Dialog'.
  • In the "Callback" field, you can enter the code that should be executed when the parameter value changes. Here, you can implement your logic to replace the block based on the selected option.
  • You can then save the mask and close the editor.
Now, when you double-click on the block, you should see the mask dialog with the desired selectable options for the “Frequency Switch” parameter. On selecting an option, corresponding code will get executed in the callback function.
Refer to the following documentation to understand more about creating callback functions in a mask:
Hope this helps you proceed further!

Categories

Find more on Author Block Masks in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!