MATLAB: Dynamically populating mask parameter popup list

dynamicmask parametersimulink

Is it possible to dynamically populate a Simulink mask's popup parameter's list using Dialog callback? Or is this facility static and to be defined while editing the mask?

Best Answer

Actually, I figured this out after hours of experimenting with Mask Parameters. This is one way to do it: You can access the 'MaskStyles' parameter like so:-
myMaskStylesVar = get_param(gcb, 'MaskStyles');
Here you should be able to observe the MaskStyles for each of your parameters as edit, checkbox, DataTypeStr, Minimum, Maximum or ...wait for it... popup! Yes, and 'popup' style is defined as follows:-
popup(menuitem1|menuitem2|menuitem3|...etc)
So you can modify the corresponding cell of myMaskStylesVar with the menu items of your choice and set them back as:-
myMaskStylesVar{1} = 'popup(red|green|blue|yellow)'; % Assuming the popup is the first parameter
set_param(gcb, 'MaskStyles', myMaskStylesVar)
You can add this code at any desired callback. In my case, I put it in 'OpenFcn'. However that led to another issue with the Mask Parameters Dialog not being invoked at the end of the code. So I had to do some crude workaround like below to invoke the Mask Parameter Dialog, but at the same time, not lose my precious code above!
a = get_param(gcb, 'OpenFcn');
set_param(gcb, 'OpenFcn', '');
open_system(gcb); %With no OpenFcn defined, this line will call Mask Parameter Dialog
set_param(gcb, 'OpenFcn', a); %Restore your original OpenFcn code
I am 99.99% sure this issue can be handled in a less comical way than above. But it works for me and my boss doesn't complain!! :)