How to link Pushbutton and Radiobutton (Matlab GUI)

2 次查看(过去 30 天)
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.

回答(1 个)

Suraj Mankulangara
Suraj Mankulangara 2018-3-13
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

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by