how can I save the selected from radio button in text file?
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
TADA
2019-2-7
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...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!