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

2 ビュー (過去 30 日間)
Tugba Ergin
Tugba Ergin 2019 年 2 月 7 日
回答済み: TADA 2019 年 2 月 7 日
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?

回答 (1 件)

TADA
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...

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by