can i change the function of a button by ussing toggle button ? like if the toggle is on the psuh button print something if not print other

답변 (1개)

Walter Roberson
Walter Roberson 2019년 5월 17일

0 개 추천

Yes.
if hObject.Value == 1
disp('something')
else
disp('other')
end

댓글 수: 3

Mazen Sallam
Mazen Sallam 2019년 5월 17일
I mean in the gui i have a sine button i want when the toggle button is off it display sin in the text style and when on display asin so what and where should i write this could ty in advanced
In the callback for the toggle button:
if hObject.Value == 1
handles.sinetextbox.String = 'sin';
else
handles.sinetextbox.String = 'asin';
end
provided that the text box had been given the label sinetextbox
Dennis
Dennis 2019년 5월 17일
I think Mazen Sallam wants to change the behaviour of a second button depending on the state of a togglebutton. In that case i would write Walters code in the callback of the second button (maybe check first if you actually need 2 buttons):
fig=figure;
handles.uihandles(3) = axes('Parent',fig,'Position',[0.375 0.375 0.4 0.4]);
handles.uihandles(1)=uicontrol('Style','Togglebutton','String','Toggle','Position',[20 100 100 40]);
handles.uihandles(2)=uicontrol('Style','pushbutton','String', 'Click me','Callback',{@simpleUI_callback,handles},'Position',[20 300 100 40]);
function simpleUI_callback(~,~,handles)
if handles.uihandles(1).Value ==1
x=-1:0.1:1;
disp(asin(x))
plot(handles.uihandles(3),asin(x))
else
x=0:0.1:2*pi;
disp(sin(x))
plot(handles.uihandles(3),sin(x))
end
end

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

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

질문:

2019년 5월 17일

댓글:

2019년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by