필터 지우기
필터 지우기

Get access to all buttongroups in my app

조회 수: 3 (최근 30일)
Henk-Jan Ramaker
Henk-Jan Ramaker 2023년 4월 7일
댓글: Henk-Jan Ramaker 2023년 4월 14일
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
Image Analyst
Image Analyst 2023년 4월 7일
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:

댓글을 달려면 로그인하십시오.

채택된 답변

Vinayak Choyyan
Vinayak Choyyan 2023년 4월 10일
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
Henk-Jan Ramaker
Henk-Jan Ramaker 2023년 4월 14일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by