How can I get the value of toggle button (uicontrol)

조회 수: 8 (최근 30일)
Mehdi
Mehdi 2015년 3월 11일
댓글: Mehdi 2015년 3월 11일
Hi fellow MATLAB users,
I have created a toggle button in a figure programmatically using uicontrol:
tb = uicontrol(gtfig, 'Style', 'togglebutton', 'String', 'Start/Stop', 'tag', 'togglebutton1', 'Position', [30 20 100 30])
How can I get its value after it's pressed? Apparently, the code:
button_state = get(hObject,'Value');
that is used in GUIDE can't be used here. Thank you for your help.

채택된 답변

Yoav Livneh
Yoav Livneh 2015년 3월 11일
You need to set a callback function for the button if you want something to happen when it is pressed. For example:
% set callback fnuction
set(tb,'Callback',@fun1);
% example for callback function
function fun1(hObject,eventData)
button_state = get(hObject,'Value');
end

추가 답변 (1개)

Mehdi
Mehdi 2015년 3월 11일
It doesn't return anything. Nothing happens when I click on it.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by