MATLAB: Button Group / make radiobutton exclusive

radiobuttonselectionchangefcnuibuttongroupuipanel

Hey guys, i have create a bunch of radiobuttons in one GUI. Now I want to make each radiobutton exclusive…. only one button can be active… if the use activates a new radiobutton the old one`s value is 0 (inactive). i have tried to use the SelectionChangeFcn but somehow it doesnt work. Can u guys give me an example with 2 radiobuttons in one panel ? i am going on to search for a solution.
Oh and pls use GUIDE in ur explaination.

Best Answer

This is a simple example from some code I just put together. A mutually exclusive radio box with two options and the SelectionChangeFcn that just prints to command window which is selected. Obviously you can do more complex stuff and store things on handles as usual within the callback.
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
str = get( hObject, 'String' );
if strcmp( str, 'Button 1' )
disp( 'Button 1' )
else
disp( 'Button 2' )
end
If it is useful here are a couple of images of the same in guide. There are other ways of programming the SelectionChangeFcn. Sometimes I use the radiobutton tags in my switch, but the above works ok. In general I think I would favour using tag though than strcmp against the string. The example works the same, just get 'Tag' instead of 'String'. It is less prone to typos than comparing a string though also a little less friendly to read.
%