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.

回答(1 个)

Adam
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.
  1 个评论
isdapi
isdapi 2014-12-1
I guess the callback function doesn't get called because when I run my script and I insert valid values and the text uicontrols go 'green' nothing happens.
So, it's very probable that you're right and I need to group them and pass them as an argument in my callback function. But I don't have any experience in doing something like that, so if you or someone could explain how to do this or point me to an example that shows how to do this, I'd be immensely grateful.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by