Linking pushbuttons to a callback function

2 Ansichten (letzte 30 Tage)
vedesh Mohit
vedesh Mohit am 21 Feb. 2020
Beantwortet: Spencer Chen am 21 Feb. 2020
function Comb_logic_circuit
ANDB = uibutton(Gate,'push','Text','AND','Position',[5 450 110 60],'ButtonPushedFcn',@(ANDB,event)AND1);
ORB= uibutton(Gate,'push','Text','OR','Position',[5 380 110 60],'ButtonPushedFcn',@(ORB,event)OR1);
NOTB = uibutton(Gate,'push','Text','NOT','Position',[5 310 110 60],'ButtonPushedFcn',@(NOTB,event)NOT1);
NANDB = uibutton(Gate,'push','Text','NAND','Position',[5 240 110 60],'ButtonPushedFcn',@(NANDB,event)NAND1);
NORB= uibutton(Gate,'push','Text','NOR','Position',[5 170 110 60],'ButtonPushedFcn',@(NORB,event)NOR1);
%Static GUI placement
InputA=uieditfield(fig,'Position',[5 500 60 40]);
InputB=uieditfield(fig,'Position',[5 350 60 40]);
InputC=uieditfield(fig,'Position',[5 200 60 40]);
Section1=uieditfield(fig,'Position',[160 570 60 50]);
Input1=uieditfield(fig,'Position',[135 600 25 20]);
Input2=uieditfield(fig,'Position',[135 570 25 20]);
Output1=uieditfield(fig,'Position',[220 585 25 20]);
Section2=uieditfield(fig,'Position',[160 400 60 50]);
Input3=uieditfield(fig,'Position',[135 430 25 20]);
Input4=uieditfield(fig,'Position',[135 400 25 20]);
Output2=uieditfield(fig,'Position',[220 415 25 20]);
Section3=uieditfield(fig,'Position',[160 200 60 50]);
Input5=uieditfield(fig,'Position',[135 230 25 20]);
Input6=uieditfield(fig,'Position',[135 200 25 20]);
Output3=uieditfield(fig,'Position',[220 215 25 20]);
Section4=uieditfield(fig,'Position',[450 570 60 50]);
Input7=uieditfield(fig,'Position',[425 600 25 20]);
Input8=uieditfield(fig,'Position',[425 570 25 20]);
Output4=uieditfield(fig,'Position',[510 585 25 20]);
Section5=uieditfield(fig,'Position',[450 400 60 50]);
Input9=uieditfield(fig,'Position',[425 430 25 20]);
Input10=uieditfield(fig,'Position',[425 400 25 20]);
Output5=uieditfield(fig,'Position',[510 415 25 20]);
Section6=uieditfield(fig,'Position',[450 200 60 50]);
Input11=uieditfield(fig,'Position',[425 230 25 20]);
Input12=uieditfield(fig,'Position',[425 200 25 20]);
Output6=uieditfield(fig,'Position',[510 215 25 20]);
Section7=uieditfield(fig,'Position',[700 570 60 50]);
Input13=uieditfield(fig,'Position',[675 600 25 20]);
Input14=uieditfield(fig,'Position',[675 570 25 20]);
Output7=uieditfield(fig,'Position',[760 585 25 20]);
Section8=uieditfield(fig,'Position',[700 400 60 50]);
Input15=uieditfield(fig,'Position',[675 430 25 20]);
Input16=uieditfield(fig,'Position',[675 400 25 20]);
Output8=uieditfield(fig,'Position',[760 415 25 20]);
Section9=uieditfield(fig,'Position',[700 200 60 50]);
Input17=uieditfield(fig,'Position',[675 230 25 20]);
Input18=uieditfield(fig,'Position',[675 200 25 20]);
Output9=uieditfield(fig,'Position',[760 215 25 20]);
Section10=uieditfield(fig,'Position',[900 400 60 50]);
Input19=uieditfield(fig,'Position',[875 430 25 20]);
Input20=uieditfield(fig,'Position',[875 400 25 20]);
Output10=uieditfield(fig,'Position',[960 415 25 20]);
OutputF=uieditfield(fig,'Position',[1070 400 60 50]);
function AND1
AP=uipanel(fig1,'Position',[280 20 300 300]);
dd=uidropdown(AP,'Position',[60 230 170 30],'Items',{'Section1','Section2','Section3','Section4','Section5','Section6','Section7','Section8','Section9','Section10'},'Value','Section1');
I1=uieditfield(AP,'text','Position',[100 100 50 30]);
I2=uieditfield(AP,'text','Position',[160 100 50 30]);
O1=uieditfield(AP,'text','Position',[125 60 50 30]);
GA=uibutton(AP,'push','Position',[100 10 100 30],'Text','Place Gate','ButtonPushedFcn',@(GA,event)selectionChanged);
function selectionChanged
val=dd.Value;
val1=text.Value;
if strcmp(val,'Section1')
if strcmp(val1,'AND')
Section1.Value = 'AND';
elseif strcmp(val1,'OR')
Section1.Value = 'OR';
elseif strcmp(val1,'NOT')
Section1.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section1.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section1.Value = 'NOR';
end
Input1.Value= I1.Value;
Input2.Value=I2.Value;
Output1.Value=O1.Value;
elseif strcmp(val,'Section2')
if strcmp(val1,'AND')
Section2.Value = 'AND';
elseif strcmp(val1,'OR')
Section2.Value = 'OR';
elseif strcmp(val1,'NOT')
Section2.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section2.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section2.Value = 'NOR';
end
Input3.Value= I1.Value;
Input4.Value=I2.Value;
Output2.Value=O1.Value;
elseif strcmp(val,'Section3')
if strcmp(val1,'AND')
Section3.Value = 'AND';
elseif strcmp(val1,'OR')
Section3.Value = 'OR';
elseif strcmp(val1,'NOT')
Section3.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section3.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section3.Value = 'NOR';
end
Input5.Value= I1.Value;
Input6.Value=I2.Value;
Output3.Value=O1.Value;
elseif strcmp(val,'Section4')
if strcmp(val1,'AND')
Section4.Value = 'AND';
elseif strcmp(val1,'OR')
Section4.Value = 'OR';
elseif strcmp(val1,'NOT')
Section4.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section4.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section4.Value = 'NOR';
end
Input7.Value= I1.Value;
Input8.Value=I2.Value;
Output4.Value=O1.Value;
elseif strcmp(val,'Section5')
if strcmp(val1,'AND')
Section5.Value = 'AND';
elseif strcmp(val1,'OR')
Section5.Value = 'OR';
elseif strcmp(val1,'NOT')
Section5.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section5.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section5.Value = 'NOR';
end
Input9.Value= I1.Value;
Input10.Value=I2.Value;
Output5.Value=O1.Value;
elseif strcmp(val,'Section6')
if strcmp(val1,'AND')
Section6.Value = 'AND';
elseif strcmp(val1,'OR')
Section6.Value = 'OR';
elseif strcmp(val1,'NOT')
Section6.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section6.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section6.Value = 'NOR';
end
Input11.Value= I1.Value;
Input12.Value=I2.Value;
Output6.Value=O1.Value;
elseif strcmp(val,'Section7')
if strcmp(val1,'AND')
Section7.Value = 'AND';
elseif strcmp(val1,'OR')
Section7.Value = 'OR';
elseif strcmp(val1,'NOT')
Section7.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section7.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section7.Value = 'NOR';
end
Input13.Value= I1.Value;
Input14.Value=I2.Value;
Output7.Value=O1.Value;
elseif strcmp(val,'Section8')
if strcmp(val1,'AND')
Section8.Value = 'AND';
elseif strcmp(val1,'OR')
Section8.Value = 'OR';
elseif strcmp(val1,'NOT')
Section8.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section8.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section8.Value = 'NOR';
end
Input15.Value= I1.Value;
Input16.Value=I2.Value;
Output8.Value=O1.Value;
elseif strcmp(val,'Section9')
if strcmp(val1,'AND')
Section9.Value = 'AND';
elseif strcmp(val1,'OR')
Section9.Value = 'OR';
elseif strcmp(val1,'NOT')
Section9.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section9.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section9.Value = 'NOR';
end
Input17.Value= I1.Value;
Input18.Value=I2.Value;
Output9.Value=O1.Value;
elseif strcmp(val,'Section10')
if strcmp(val1,'AND')
Section10.Value = 'AND';
elseif strcmp(val1,'OR')
Section10.Value = 'OR';
elseif strcmp(val1,'NOT')
Section10.Value = 'NOT';
elseif strcmp(val1,'NAND')
Section10.Value = 'NAND';
elseif strcmp(val1,'NOR')
Section10.Value = 'NOR';
end
Input19.Value= I1.Value;
Input20.Value=I2.Value;
Output10.Value=O1.Value;
end
end
end
end
Hi i have attempted to create a static GUI where i have five pushbuttons, where the user can select a respective section to place the gate. So far I was able to get it to work for one pushbutton but while attempting to add the other four pushbuttons, I was unsuccesful as only the 'AND' button is working. Can anyone advise on the code above to incoprorate the other four pusbuttons('OR','NOT','NAND'&'NOR') with the callback function selectionChanged.

Antworten (1)

Spencer Chen
Spencer Chen am 21 Feb. 2020
I think the problem may lie in that you have nested your functions such that selectionChanged() is a nested function of AND1(). In which case, functions the same same level of AND1() has not access to it. You probably want to implement selectionChanged() at a higher hierarchy.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by