Dynamically populating mask parameter popup list
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Arun
el 23 de Jul. de 2013
Comentada: checker
el 14 de Feb. de 2021
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?
1 comentario
Respuesta aceptada
Arun
el 14 de Ag. de 2013
6 comentarios
Jared Belke
el 26 de Jun. de 2019
Editada: Jared Belke
el 26 de Jun. de 2019
I know this is super late, but since this is what I work on every day I figured I'd update this for people who see this post now. There is a less comical way to do it. Assume you have some cell array "options" that contains the new list of options that you want to populate the popup list with. You can do the following:
maskObj = Simulink.Mask.get(gcb);
maskObj.getParameter('<Name of Popup List Parameter>').TypeOptions = options;
You can also do many other things with the Mask Object such as dynamically change the Enable field, Visible field, Value field (Or any other field that you can edit in the mask editor) of any Parameter or Dialog Control (E.g. Buttons).
For example:
maskObj.getParameter('<Name of Parameter>').Enabled = 'off';
maskObj.getParameter('<Name of Button>').Visible = 'on';
checker
el 14 de Feb. de 2021
Jared, thanks buddy, that's awesome. I've moved from older versions of matlab to 2020 and have been finding lots of new APIs but this one eluded me until I ran across your post.
Más respuestas (2)
Kaustubha Govind
el 14 de Ag. de 2013
I'm not much of an expert in the Simulink Mask area, but I don't think you can dynamically change the contents of a mask. However, you can change the visibility of parameters - so you might want to create multiple popup lists for each configuration and change their visibility in the Dialog Callback.
2 comentarios
Robert
el 20 de En. de 2015
If you find this thread, it helps to be clear on what is meant by "Dynamic". I have found that you may dynamically update a mask, e.g. in an OpenFcn callback. However if you wish the mask to be dynamic once open (e.g. two drop-down-lists/popups where the choices in the second depend on the selected value of the first) this does not seem to be possible. However this type of dynamic functionality is achievable via a custom GUI (see GUIDE help).
Matthew
el 18 de Nov. de 2016
Editada: Matthew
el 18 de Nov. de 2016
It turns out there is a simple DAStudio functionality that allows masks to be dynamic once open.
dToolRoot = DAStudio.ToolRoot;
openDialogs = dToolRoot.getOpenDialogs;
openDialogs(1).refresh();
Or
blockObject = get_param(gcb,'object');
blockDialog = DAStudio.Dialog(blockObject.getDialogSource);
blockDialog.refresh();
I'll add a full code sample as an answer.
Matthew
el 18 de Nov. de 2016
Editada: Matthew
el 18 de Nov. de 2016
If you want to update a popdown menu while a mask is open, the following may be helpful:
% Set the parameter index equal to the index specified
% for the desired popup parameter in the mask editor
parameterIndex = 1;
% Get the handle to the mask parameter to modify
maskHandle = Simulink.Mask.get(gcb);
maskParameters = maskHandle.Parameters;
% Update the popup list options
maskParameters(parameterIndex).TypeOptions = {'Option 1', 'Option 2'};
% Now refresh the mask display
%Get the handle to the blocks object
blockObject=get_param(gcb,'object');
%Get the handle to the dialog
blockDialog= DAStudio.Dialog(blockObject.getDialogSource);
%Refresh the dialog
blockDialog.refresh();
0 comentarios
Ver también
Categorías
Más información sobre Interactive Model Editing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!