How to link Pushbutton and Radiobutton (Matlab GUI)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Suraj Mankulangara
am 13 Mär. 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
1 Kommentar
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!