How to obtain the text of the selected radio button group in app designer?

조회 수: 25 (최근 30일)
Dear Community
I'm using the app designer to create a radio button group, and I intended to obtain the 'text' of the selection and save it to work space. Right now my code does save the current selection to workspace, but i notice that it only works if I changed the selection. (ie, if I swich from "choice A" to "choice B" or "choice c" then it will save, but if I left it in default "choice A" it stores nothing)
I was wondering how can I resolve this, or perhaps there is another way to save the selection.
here's my callback function for the radio button group
% Selection changed function: GratingPeriodButtonGroup
function GratingPeriodButtonGroupSelectionChanged(app, event)
selectedButton = app.GratingPeriodButtonGroup.SelectedObject.Text;
app.GratingPeriod = selectedButton ;
end
here's the callback funciton of the pushbutton that save the value to workspace
% Button pushed function: StartButton
function StartButtonPushed(app, event)
assignin('base','GratingPeriod',app.GratingPeriod)
closereq;
end

채택된 답변

Kojiro Saito
Kojiro Saito 2019년 3월 29일
I think you need to add assign an initial value to app.GratingPeriod.
From Code Browser in Code View, click "+" button and add a "StartupFcn" callback function.
2019329213555.jpg
Then, write an assignment to app.GratingPeriod.
function startupFcn(app)
app.GratingPeriod = app.Button.Text;
end
Please change app.Button to the actual button name whose value is "choice A".

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by