Cannot set handles in Radio Button Group
3 views (last 30 days)
Show older comments
Hello, I am having a great deal of difficulty setting the handles for a group of radio buttons included within a panel that dictate which menu selections are available on a pop up menu. Here’s the “low-down” I am first resetting all handles to zero.
set(handles.r1_5800,'Value',0);
set(handles.r1_9800,'Value',0);
set(handles.r2_5800,'Value',0);
set(handles.r2_9800,'Value',0);
then I am calling a function which monitors the selection changes of the part panel where the radio buttons reside.
set(handles.partPanel,'SelectionChangeFcn',@partPanel_SelectionChangeFcn);
% Update handles structure
guidata(hObject, handles);
The function for the four radio buttons and how they relate to the menu is here further on in the code % --- Executes when selected object is changed in partPanel. function partPanel_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to the selected object in partPanel % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
%ctqString = [];
switch (get(eventdata.NewValue,'Tag'))
case 'r1_5800'
%
set(handles.r1_5800,'Value', 1);
ctqString = {'Noise | Offset | Gain'};
case 'r1_9800'
%
set(handles.r1_9800,'Value', 1);
ctqString = {'Noise | Offset | Gain'};
case 'r2_5800'
%
set(handles.r2_5800,'Value', 1);
ctqString = {'Noise | Offset | Gain'; 'Calibration'; 'Leakage'; 'Trim'};
case 'r2_9800'
%
set(handles.r2_9800,'Value', 1);
ctqString = {'Noise | Offset | Gain'; 'Calibration'; 'Leakage'; 'Trim'};
otherwise
% do nothing
end
set(handles.ctqMenu, 'String', ctqString);
Once this is run the handles of a single button should be set to ‘1’
Now when I hit the “Start” button and try to run the thing
if (isReadyToTest)
rev1_5800 = get(handles.r1_5800,'Value');
rev1_9800 = get(handles.r1_5800,'Value');
rev2_5800 = get(handles.r1_5800,'Value');
rev2_9800 = get(handles.r1_5800,'Value');
if ~(rev1_5800 || rev1_9800 || rev2_5800 || rev2_9800)
msgbox('Select a VyGem part in the part selection panel','Input Error', 'error');
isReadyToTest = 0;
else
isReadyToTest = 1;
end
end
all of the rev1 _5800 though rev2_9800 are still set to zero nulling out any selection I made. Any suggestions? I’ve set break points right at the if (isReadyToTest) and see that the handles weren’t set at all
Thanks Bill
1 Comment
Fangjun Jiang
on 29 Jun 2011
Replace with
switch(get(hObject,'Tag'))
No need to set(handles.r1_5800,'Value', 1)
Accepted Answer
Paulo Silva
on 29 Jun 2011
Why do you reset all the radio buttons of the Radio Button Group? that doesn't make sense because the group must have one radio button selected.
3 Comments
Paulo Silva
on 29 Jun 2011
first check if the SelectionChangeFcn is really being executed, just put it sending something to the command line ex: disp('SelectionChangeFcn') , if it's working properly check what you get with get(eventdata.NewValue,'Tag') , just put that line before the switch and see what does it return on the command line
More Answers (1)
Fangjun Jiang
on 29 Jun 2011
Are you constructing your GUI using GUIDE or manually writing .m code? When you put 4 radio buttons in a panel (button group), they are mutual-exclusive, so I don't think you can set all there initial value as 0. One of them has to be 1.
In the SelectionChangeFcn callback, you don't need to set the 'value' property of the radio button. The callback function of the radio button is over-written by the button group SelectionChangeFcn callback. When you select any of those four buttons, the 'value' property is automatically updated. All you need is to read the 'Tag' property of the radio button, do different things in the switch-case statement. Don't worry about the handle or value of the radio buttons.
10 Comments
Fangjun Jiang
on 29 Jun 2011
It was mentioned in the comment generated by GUIDE for the SelectionChangeFcn for the button group.
%hObject handle to the selected object in uipanel
I use GUIDE to develop my GUI. So in my SelectionChageFcn, disp(get(hObject,'Tag')) is enough to show how button group works. What is your usual way to do things differently based on button group selection?
Paulo Silva
on 29 Jun 2011
You are correct and I didn't noticed that before, never used the SelectionChageFcn until now, my only use of the button group is to have only one radio button selected, usually use the value of radiobuttons inside if conditions just before executing important code.
See Also
Categories
Find more on Startup and Shutdown 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!