toggle button control checkboxes that each has a slider

3 次查看(过去 30 天)
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 中查找有关 App Building 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by