Radio Button and Panel GUIDE

What code should i write under a callback of the radio button when you want to click a radio button, the visibility of the panel is being controlled. Radio button clicked, Panel appears. Radio Button unclick, panel hides...what do you think? Thank you everyone

1 Comment

the panel---i mean a panel you created on a gui...so only two objects are present on the gui. The radio button and a panel...thank you

Sign in to comment.

Answers (1)

G A
G A on 24 Feb 2012
if (get(hObject,'Value') == get(hObject,'Max'))
set (handles.my_uipanel,'Visible','on');
else
set (handles.my_uipanel,'Visible','off');
end

8 Comments

i tried this but still it doesn't work, what do you think is wrong? or am i missing something else?
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton3
if get(hObject,'Value')
set (handles.panelgen,'Visible','on');
else
set (handles.panelgen,'Visible','off');
end
but it worked when i used a checkbox instead of a radiobutton...does the button group caused my problem? since i used a button group for my radiobutton...
may be you have to use this line:
if (get(hObject,'Value') == get(hObject,'Max'))
"Radio buttons set Value to Max when they are on (when selected) and Min when off (not selected)."
http://www.mathworks.co.uk/help/techdoc/creating_guis/f16-999044.html#f16-1003665
i used this, and it worked...
function uipanel5_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel5
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'radiogen'
% Code for when radiobutton1 is selected
set (handles.panelgen,'Visible','on');
set (handles.panelmot,'Visible','off');
case 'radiomot'
% Code for when radiobutton2 is selected.
set (handles.panelmot,'Visible','on');
set (handles.panelgen,'Visible','off');
otherwise
% Code for when there is no match.
end
I have edited the code above
what changes have you made?
Instead of checking for Value 1 or 0 (true or false), for radio button you have to check for Value 'Max' or 'Min'
hello, i want to show panel with some texts when i click push button only and hide it when i am not click it. any help? thanks

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 24 Feb 2012

Commented:

on 16 May 2017

Community Treasure Hunt

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

Start Hunting!