How to create dynamic options in system object block mask parameters

8 次查看(过去 30 天)
I want to make the dropdown content of one system object parameter based on the value of another parameter. In other words, Timer 1 may support options A, B and C, while Timer 2 would only support options A and B. I can do this in a standard subsystem block mask by modifying the option parameter dropdown content on the callback for the timer parameter. MATLAB system objects only seem to support defining dropdown content for their parameters statically. Is this possible?

回答(1 个)

Rahul
Rahul 2024-8-13
In order to dynamically assign properties of Block Mask Parameters in Simulink, I have assumed a case of two Dropdown parameters of type ‘Popup’, one of which displays different options depending upon the value selected in the other:
1. Create ‘Popup’ Parameters
Navigate to Subsystem > Mask Editor > Parameters & Dialog and select Popup under Parameters section on the left twice, creating two parameters ‘DropDown1and ‘DropDown2’.
For simplicity, while selecting ‘DropDown1’ in the same panel, under properties section on the right, assign the property ‘TypeOptions’ as “A, B, C”.
2. Assign CallbackNavigate to Subsystem > Mask Editor > Code and click on ‘+’ next to ‘DropDown1’ to add a static callback method, and use the following code snippet in the function definition:
function DropDown1(callbackContext)
val = get_param(gcb, 'DropDown1');
options = '';
% Define options for Dropdown2 based on the selection of Dropdown1
switch val
case 'A'
options = 'Desc1|Desc2';
case 'B'
options = 'Desc1|Desc3';
case 'C'
options = 'Desc2|Desc3';
end
% Update the Dropdown2 parameter
maskObj = Simulink.Mask.get('test5_model/Subsystem1');
params = maskObj.Parameters(2);
params.TypeOptions = strsplit(options, '|');
end
This allows the callback function to be triggered at every value selection of ‘DropDown1’ parameter, which sets TypeOptions properties of 'DropDown2' (in this case, a combination of {‘Desc1’, ‘Desc2’, ‘Desc3’}) depending on currently selected option Value property of 'DropDown1'.
For more information regarding mask parameter properties of Simulink block objects and how to programmatically update those respectively, kindly refer to the documentation below:
  1 个评论
Jeremy
Jeremy 2024-8-13
As I stated in the original post, I am fully aware of how to do this in a typical block mask. I was trying to do this in the mask of a MATLAB System Block, which is defined in a matlab.system object.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Schedule Model Components 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by