How to create dynamic options in system object block mask parameters
6 ビュー (過去 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?
0 件のコメント
回答 (1 件)
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 ‘DropDown1’ and ‘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:
参考
カテゴリ
Help Center および File Exchange で Schedule Model Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!