Help defining a callback to enable a pushbutton
6 次查看(过去 30 天)
显示 更早的评论
Hi, in a long script that I'm working on, I don't manage that a pushbutton is activated when something happens. Here's the code:
%Tex uicontrols that once they change to a specific colour, which means the user input is correct, then they enable a pushbutton.
texpd0 = uicontrol(pdp,'Style','text','String','Drop Height:','BackgroundColor',[.88 .88 .88],'Position',[15 85 125 20],'FontSize',12,'Callback',@act);
expd2 = uicontrol(pdp,'Style','text','String','PI Elevation:','BackgroundColor',[.88 .88 .88],'Position',[15 25 125 20],'FontSize',12,'Callback',@act);
texpd4 = uicontrol(pdp,'Style','text','String','ISA dev:','BackgroundColor',[.88 .88 .88],'Position',[200 200 80 20],'FontSize',12,'Callback',@act);
texpd5 = uicontrol(pdp,'Style','text','String','IASact:','BackgroundColor',[.88 .88 .88],'Position',[200 170 80 20],'FontSize',12,'Callback',@act);
%This is the pushbutton that should be enabled. Default is unabled.
edt6a = uicontrol(pdp,'Style','pushbutton','String','Update TAS','Position',[360 140 70 20],'Enable','off','Callback',@update)
%Here the callback function of the tex uicontrols:
function act
cond0 = get(texpd0,'BackgroundColor');
cond1 = get(texpd2,'BackgroundColor');
cond2 = get(texpd4,'BackgroundColor');
cond5 = get(texpd5,'BackgroundColor');
ok = [.88 .96 .88];
if isequal(cond0,ok) && isequal(cond1,ok) && isequal(cond2,ok) && isequal(cond5,ok)
set(edt6a,'Enable','on');
else
set(edt6a,'Enable','off');
end
end
So what I want to achieve is that when all these tex uicontrols change its backgroundcolor to [.88 .96 .88], then the pushbutton is enabled.
0 个评论
回答(1 个)
Adam
2014-12-1
In what way does it not work? Does the act function even get called? If it does I'm guessing from your function signature that it has an empty workspace since it takes no input arguments.
From what you have written the 'act' function will not know what texpd0 and the others are. You would likely need to put these all together in a struct and pass that to your act function as an input argument.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!