Constant Blocks Value Change under mask
12 views (last 30 days)
Show older comments
Hello,
I developed a Simulink model with lots of inputs. The model is working perfectly, however I want to make it more useful. I masked my constant blocks (12 constant blocks) and I made sliding buttons, radio buttons etc. Now I cannot change the values of constant blocks. I can move sliders and dials but they are not effect the value. I promoted their constant values but still I cannot change it. Is there anyone can help me ?
Kind regards,
Ege
2 Comments
Answers (1)
Tejas
on 16 Feb 2024
Hello Ege,
To modify the values of Constant blocks through a mask, you should begin by defining parameters that correspond to each block within the Mask Editor.
After setting up these parameters, you'll need to create a mask initialization callback. Within this callback, you can employ the 'set_param’ function to update the values of the Constant blocks to your desired figures.
Here is a screenshot for your reference, showcasing the corresponding parameters for the constant block.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1618878/image.png)
In the code section of Mask editor, create a Mask Initialization callback , and enter the following code :
function MaskInitialization(maskInitContext)
set_param( [gcb '/Constant_1'], 'Value', 'Val_const1');
set_param( [gcb '/Constant_2'], 'Value', 'Val_const2');
set_param( [gcb '/Constant_3'], 'Value', 'Val_const3');
end
Here “Constant_1”, “Constant_2”, “Constant_3” are the labels assigned to constant blocks in Simulink model.
This solution is tested on MATLAB R2023b. For more information about 'set_param' function please refer to this documentation : https://www.mathworks.com/help/simulink/slref/common-block-parameters.html#:~:text=Simulink.VariantConfigurationData%20object.-,Examples%20of%20Setting%20Block%20Properties,%27mymodel/Gain%27%2C%27Position%27%2C%5B50%20250%20125%20275%5D),-See%20Also .
Hope this helps!
0 Comments
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!