Clear Filters
Clear Filters

How to link Pushbutton and Radiobutton (Matlab GUI)

4 views (last 30 days)
Want to implement a process like when a radio button1 is select and press a pushbutton then code will be executed for radio button1 likewise 2 other radio buttons. I tried many ways but stuck in errors. Please help me how to implement this process.

Answers (1)

Suraj Mankulangara
Suraj Mankulangara on 13 Mar 2018
Hello Durgesh
I understand that you have multiple radio buttons and a push button, and that when the push button is clicked, you want to perform a different action depending upon which radio button is selected.
I have outlined steps below that you could follow to resolve this issue:
1) You may want to write a callback function for the push button. The actions that you want to perform when the push button is clicked can be embedded into the callback. This link will give you more information about how to write callback functions in MATLAB:
2) You could tag your radio button with the 'Tag' property while creating your uicontrol, giving each radiobutton a unique name.
3) You can search for the uicontrol with the tag by using the findobj function:
4) Once you have the handle to the required radio button, you can query it's Value property. For radio buttons, the Value property will be 0 if the radio button is unselected, and 1 if the radio button is selected.
The following sample code should illustrate this:
f = figure;
btn = uicontrol('Style', 'pushbutton', 'String', 'PushMe', 'Position', [20 340 100 50], ...
'Callback', @pushButtonCallBack);
radio = uicontrol('Style', 'radiobutton', 'Position', [400 20 120 20], 'Tag', 'radio');
function pushButtonCallBack(src, event)
r = findobj('Tag', 'radio');
disp(r.Value);
end

Categories

Find more on Migrate GUIDE Apps 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!