How do I create loop, where conditions equal pushed radio buttons?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I want my program to have certain values that will be chosen based on "ticked" radio buttons. For example if option 1 was chosen, first variable equals 10, for second option variable equals 5 and so on. I'm using "if statement".
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 1월 20일
Example adapted from the uibuttongroup documentation:
bg = uibuttongroup('Visible','off',...
'Position',[0 0 .2 1];
% Create three radio buttons in the button group.
r1 = uicontrol(bg,'Style',...
'radiobutton',...
'String','10',...
'Position',[10 350 100 30],...
'HandleVisibility','off');
r2 = uicontrol(bg,'Style','radiobutton',...
'String','5',...
'Position',[10 250 100 30],...
'HandleVisibility','off');
r3 = uicontrol(bg,'Style','radiobutton',...
'String','17',...
'Position',[10 150 100 30],...
'HandleVisibility','off');
set(bg, 'SelectedObject', []);
Then at the time you want to know what the value is:
sel = get(bg, 'SelectedObject');
if isempty(sel)
warndlg('You have not selected a value yet!');
else
sel_str = get(sel, 'String');
sel_value = str2double(sel_str);
... now use sel_value in your computation
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!