MATLAB Answers

0

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

Asked by Guandong Wang on 29 Mar 2019
Latest activity Answered by Kojiro Saito on 29 Mar 2019
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Kojiro Saito on 29 Mar 2019
 Accepted Answer

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 Comments

Sign in to comment.