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

13 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 29 Mär. 2019
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".

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by