フィルターのクリア

How to link Pushbutton and Radiobutton (Matlab GUI)

2 ビュー (過去 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by