Is it possible to add custom block parameters to Simulink blocks in Simulink 7.8 (R2011b)?

1 view (last 30 days)
I would like to add custom parameters to built-in blocks in my Simulink model. For example, if the model, 'myModel' contains the Gain Block, 'gain1' I would like to add a parameter 'myParam' to this block so that I may access it via:
get_param('myModel/gain1', 'myParam')
set_param('myModel/gain1', 'myParam', some_value)
Moreover, I would like for the value of the parameter to persist after I save and close the model's MDL file.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Nov 2011
The ability to add custom parameters to built-in blocks is not available in Simulink 7.8 (R2011b). To work around this issue, starting in Simulink 7.8 (R2011b) it is possible to mask built-in blocks which do not already have a mask. This may be done by right-clicking on the block and choosing 'Create Mask'. Within the Mask Editor dialog, block parameters may be added to the block that are accessible via the functions GET_PARAM and SET_PARAM.
In versions before Simulink 7.8 (R2011b), the block parameter 'UserData' may be used to store the desired values. Also, the parameter 'UserDataPersistent' may be set to 'on' in order to save the data stored in 'UserData' in the model file. For example:
set_param('myModel/gain1', 'UserData', myData)
set_param('myModel/gain1', 'UserDataPersistent', 'on')
would save the value 'myData' in 'UserData' and specify that it should be stored in the MDL file after the model is saved and closed.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!