toggle button control checkboxes that each has a slider

조회 수: 5 (최근 30일)
Kuang-Yu WANG
Kuang-Yu WANG 2018년 7월 26일
댓글: Adam 2018년 7월 26일
i want to use toggle with checkboxes that can control the buttons as for buttons can be push at the same time. however what i do can only move one button. please help.
toggleforall = uicontrol('Style','Togglebutton',...
'String','Pumping Stop',...
'Units','Normalized',...
'BackgroundColor',GUI.menucolor,...
'Position',[.58 .80 .05 .04],'Tag','tbfa','callback',@pumpcontrol);
checkbox1=(f,'Style','checkbox','UserData','Pump1',...
'Units','Normalized','Value',0,...
'Position',[.73 .37 .02 .02]);
checkbox2=(f,'Style','checkbox','UserData','Pump2',...
'Units','Normalized','Value',0,...
'Position',[.74 .37 .02 .02]);
slider1=uicontrol(f,'Style','slider',...
'Min',0,'Max',100,'Value', 0,...
'SliderStep',[0.05 0.2],'Tag','slider1',...
'Units','Normalized','Position',[.78 .66 .08 .04]);
slider2=uicontrol(f,'Style','slider',...
'Min',0,'Max',100,'Value', 0,...
'SliderStep',[0.05 0.2],'Tag','slider2',...
'Units','Normalized','Position',[.79 .66 .08 .04]);
function pumpcontrol(hObject, eventdata, handles)
val=get(hObject,'value');
check = get(hObject, 'UserData');
if check ~= 0
if val==1 % button down
set(hObject,'BackgroundColor',GUI.offcolor,... %yellow = pump running
'string',[get(hObject, 'UserData') ' running'],'FontSize',10);
if check == slider1
GUI.p1Running = 1;
p1.ts = 0;
p1.num = str2num(get(textbox1,'String'));
ps=get(GUI.button(check),'Max')-get(GUI.button(check),'value')+20;
set(p1.t, 'Period', ps/1000); %the number can change pumping speed
start(p1.t);
elseif check == slider2
check = slider2;
GUI.p2Running = 1;
p2.ts = 0;
p2.num = str2num(get(GUI.button(check+1),'String'));
ps=get(GUI.button(check),'Max')-get(GUI.button(check),'value')+20;
set(p2.t, 'Period', ps/1000);
start(p2.t);
end
  댓글 수: 1
Adam
Adam 2018년 7월 26일
if check == slider1
is not going to work. I am assuming your function is a nested function, although it is impossible to tell from the code you posted. If it isn't then slider1 is not in scope in the function pumpcontrol.
Mostly though slider1 is a uicontrol, check is a boolean. why are you trying to compare them for equality?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by