How to create dynamic options in system object block mask parameters
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Rahul
el 13 de Ag. de 2024
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:
Ver también
Categorías
Más información sobre Schedule Model Components en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!