How to link Pushbutton and Radiobutton (Matlab GUI)

조회 수: 1 (최근 30일)
Durgesh Birhade
Durgesh Birhade 2018년 3월 4일
댓글: jay shah 2020년 8월 3일
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
  댓글 수: 1
jay shah
jay shah 2020년 8월 3일
can you please explain the first one in detail?

댓글을 달려면 로그인하십시오.

카테고리

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