how can I save the selected from radio button in text file?

2 views (last 30 days)
There are 60 questions in a survey. There are 9 options for each question with radio buttons. When one of these 9 options is selected with radio buttons, how do I print or write the selected one in the text file? which code should I use? For each question you have these same 9 options. How can I show it in the text file?

Answers (1)

TADA
TADA on 7 Feb 2019
It realy depends on the design of your GUI
do you have a submit button or do you capture the selection of the radio button?
If you are using a uibuttongroup to achieve the radio behavior, you can use it to get the selected radio button, then you can get its text or whatever
lets say you have this figure:
figure();
h.grp = uibuttongroup(gcf, 'Units', 'norm', 'Position', [0.25, 0.25, 0.5, 0.5]);
h.r1 = uicontrol(h.grp, 'Units', 'norm', 'Position', [0, 0.7, 1, 0.3], 'Style', 'radiobutton', 'String', 'text 1');
h.r2 = uicontrol(h.grp, 'Units', 'norm', 'Position', [0, 0.35, 1, 0.3], 'Style', 'radiobutton', 'String', 'text 2');
set(h.r1, 'Value', 0);
set(h.r2, 'Value', 0);
now you can capture the selection chnaged event of the button group and do something with the selected radio button like that:
set(h.grp, 'SelectionChangedFcn', @(src, arg) disp(src.SelectedObject.String));
obviously this functionality to display the text of the selected radio button to the command window is useless, but you can subscribe just about any function to the changed event and save that value in a variable, analyze it, save it to a file or what ever you like...

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!