Borrar filtros
Borrar filtros

Get access to all buttongroups in my app

4 visualizaciones (últimos 30 días)
Henk-Jan Ramaker
Henk-Jan Ramaker el 7 de Abr. de 2023
Comentada: Henk-Jan Ramaker el 14 de Abr. de 2023
I have created an app that can be used as a questionnaire. There are several tabs. On each tab, there is a buttongroup with radiobuttons. E.g. for the question "what is your sex" there are two answers possible: male or female. The initial answer is "female" in this case. The user can navigate to the next tab where there is another question and so on. When the user reaches the end, I want to reset the questionnaire. So, each radiobuttongroup should be initialized again. If somebody selected "male" it shoud be reset to "female" again,
How can I cycle through all possible buttongroups inside startFcn to record the initial state? I cannot get findall or findobj to work for this purpose, it gives me nothing but an empty graphics holder. To make it clear: I don't want to use the hard wired names I gave to the ButtonGroups, I want them to be found & selected programatically. And how can I use the initial states collected during the startFcn in order to initialize all the buttongroups again when a reset is requested?
  1 comentario
Image Analyst
Image Analyst el 7 de Abr. de 2023
You forgot to attach your .mlapp file.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Iniciar sesión para comentar.

Respuesta aceptada

Vinayak Choyyan
Vinayak Choyyan el 10 de Abr. de 2023
Hi Henk-Jan Ramaker,
As per my understanding, you are trying to reset some radio button groups. You would like to do this programmatically and not by calling them by name.
Please find the attached MATLAB app file. In this example file, I have added a private property named ‘defaultButtonGroup’. This variable is used to store the default values of all radio button groups. Within the ‘startupFcn’, we save all the initial values. Then when the ‘Reset’ button is clicked, within the ‘ResetButtonPushed’ callback function, we reassign the default values back to all the radio groups.
As you have not posted your code, I have taken to liberty of making a simple app example. Please modify the example as per your use case.
Please feel free to check out the following link https://www.mathworks.com/help/matlab/ref/matlab.ui.container.buttongroup-properties.html#bujxo9x-79-SelectedObject to read more about the ‘SelectedObject’ property of ‘ButtonGroup’.
I hope this resolves he issue you are facing.
  1 comentario
Henk-Jan Ramaker
Henk-Jan Ramaker el 14 de Abr. de 2023
Dear Vinayak, many thanks for your answer. The solution you offered works almost out-of-the-box.
The app I have build (and all the items it contains) are captured inside a grid layout. If I use your first piece of code that runs in the startupFcn of my app, the only element(s) found is this GridLayout:
tmp =
GridLayout with properties:
RowHeight: {'1x' 'fit' [50]}
ColumnWidth: {'1x' [198] '1x'}
Position: [1 1 856 629]
Therefore, I have changed this line of code:
app.allElements = app.UIFigure.Children;
to this:
allElements = findobj(app.UIFigure);
This seems to solve problem since now all the elements are available.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown 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!

Translated by