How to avoid too many if else statements











up vote
0
down vote

favorite












I am writing a simple app using matlab app designer, My code works but I want to make it better. I have too many if else conditions. How can I avoid this? I use matlab app designer, I take 3 values and compare them again and again with different sets



 function buttonpush3Act(app, event)
a3= app.StrokeLengthmmEditField_13.Value;
b3=app.StrokeLengthmmEditField_12.Value;
c3= app.StrokeLengthmmEditField_11.Value;
d3=app.BuildingDimensionmmEditField_6.Value;
e3=app.BuildingDimensionmmEditField_5.Value;
f3=app.BuildingDimensionmmEditField_4.Value;
g3=app.orPreconfiguredrefnumEditField.Value;
h3=app.orPreconfiguredrefnumEditField_2.Value;
i3=app.orPreconfiguredrefnumEditField_3.Value;
j3=app.ActuatorTypeNumberEditField.Value;
k3=app.ActuatorTypeNumberEditField_2.Value;
l3=app.ActuatorTypeNumberEditField_3.Value;


%reset message field
app.OutputMessageEditField_2.Value= "";
% avoid missuse of the ´result´button
if(a3==0 && b3==0 && c3==0 && d3==0 && e3==0 && f3==0 && g3==0 && h3==0)
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value ='';

%check for pre configured actuators



elseif((j3== k3 == l3 || j3== k3 || j3== l3 || k3 == l3) && (j3 > 0 && k3 > 0 && l3 > 0)) %avoid having more than one LA40
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value =" ERROR2: Unsupported configuration";

%check if special actuators present
elseif((j3 == 40 && k3 ~= 40 && l3 ~= 40) || (j3 ~= 40 && k3 == 40 && l3 ~= 40) || (j3 ~= 40 && k3 ~= 40 && l3 == 40))
% a rotation to to catch la 40 and define it as ref4
dataLa40 = [j3,k3,l3];
ref4 = dataLa40(1)
for r= 1:length(dataLa40)
if dataLa40(r) == 40;
ref4 = dataLa40(r);
end
end
if (ref4 == dataLa40(1))
app.Actuator1EditField.Value = "ref4";
elseif(ref4 == dataLa40(2) )
app.Actuator2EditField.Value = "ref4";
else(ref4 == dataLa40(3))
app.Actuator3EditField.Value = "ref4";
end





% if act1== ref4 what if act2== ref4 what if act3== ref4 what

%check for rule D
elseif((a3 ~= b3) && (a3~= c3) && (b3 ~= c3) && (a3 > 0 && b3 > 0 && c3 > 0))

data= [a3,b3,c3];
ref2= data(1)
ref3=data(1)
ref1=data(1)
for j = 1:length(data)
%largest stroke length
if data(j)>ref2;
ref2=data(j);
end
end
for k = 1:length(data)
%smallest stroke length
if data(k)<ref3;
ref3=data(k);
end
end

for m = 1:length(data)
%stroke length in the middle
if ref3<data(m) & data(m)<ref2;
ref1=data(m);
end
end

if (ref2== a3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==b3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==c3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==a3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==b3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==c3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==a3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==b3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==c3)
app.Actuator3EditField.Value= "ref1" ;
end
% elseif((a3 == b3) || (a3 == c3) || (b3 == c3))
%check for rule C
else(((a3 == b3) || (a3 == c3) || (b3 == c3)) && (a3 > 0 && b3 > 0 && c3 > 0))

data_list= [d3,e3,f3];
ref2= data_list(1)
ref3=data_list(1)
ref1=data_list(1)
for n = 1:length(data_list)
%largest Building Dimension
if data_list(n)>ref2;
ref2=data_list(n);
end
end
for p = 1:length(data_list)
%smallest Building Dimension
if data_list(p)<ref3;
ref3=data_list(p);
end
end

for q = 1:length(data_list)
%Building Dimension in the middle
if ref3<data_list(q) & data_list(q)<ref2;
ref1=data_list(q);
end
end



if (ref2== d3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==e3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==f3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==d3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==e3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==f3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==d3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==e3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==f3)
app.Actuator3EditField.Value= "ref1" ;
end

%check for eqaul building dimentions
if(((d3 == e3) || (d3 == f3) || (e3 == f3)) && (d3 > 0 && e3 > 0 && f3 > 0))
app.OutputMessageEditField_2.Value ="Use channel assignment or config. tool";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

else
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

end
end
%should be out of main loop, independent
if(a3 == 0 ||b3 == 0 ||c3 == 0 ||d3 == 0 ||e3 == 0 ||f3 == 0 ||j3 == 0 ||k3 == 0 ||l3 == 0 )
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
end
end









share|improve this question









New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 hours ago















up vote
0
down vote

favorite












I am writing a simple app using matlab app designer, My code works but I want to make it better. I have too many if else conditions. How can I avoid this? I use matlab app designer, I take 3 values and compare them again and again with different sets



 function buttonpush3Act(app, event)
a3= app.StrokeLengthmmEditField_13.Value;
b3=app.StrokeLengthmmEditField_12.Value;
c3= app.StrokeLengthmmEditField_11.Value;
d3=app.BuildingDimensionmmEditField_6.Value;
e3=app.BuildingDimensionmmEditField_5.Value;
f3=app.BuildingDimensionmmEditField_4.Value;
g3=app.orPreconfiguredrefnumEditField.Value;
h3=app.orPreconfiguredrefnumEditField_2.Value;
i3=app.orPreconfiguredrefnumEditField_3.Value;
j3=app.ActuatorTypeNumberEditField.Value;
k3=app.ActuatorTypeNumberEditField_2.Value;
l3=app.ActuatorTypeNumberEditField_3.Value;


%reset message field
app.OutputMessageEditField_2.Value= "";
% avoid missuse of the ´result´button
if(a3==0 && b3==0 && c3==0 && d3==0 && e3==0 && f3==0 && g3==0 && h3==0)
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value ='';

%check for pre configured actuators



elseif((j3== k3 == l3 || j3== k3 || j3== l3 || k3 == l3) && (j3 > 0 && k3 > 0 && l3 > 0)) %avoid having more than one LA40
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value =" ERROR2: Unsupported configuration";

%check if special actuators present
elseif((j3 == 40 && k3 ~= 40 && l3 ~= 40) || (j3 ~= 40 && k3 == 40 && l3 ~= 40) || (j3 ~= 40 && k3 ~= 40 && l3 == 40))
% a rotation to to catch la 40 and define it as ref4
dataLa40 = [j3,k3,l3];
ref4 = dataLa40(1)
for r= 1:length(dataLa40)
if dataLa40(r) == 40;
ref4 = dataLa40(r);
end
end
if (ref4 == dataLa40(1))
app.Actuator1EditField.Value = "ref4";
elseif(ref4 == dataLa40(2) )
app.Actuator2EditField.Value = "ref4";
else(ref4 == dataLa40(3))
app.Actuator3EditField.Value = "ref4";
end





% if act1== ref4 what if act2== ref4 what if act3== ref4 what

%check for rule D
elseif((a3 ~= b3) && (a3~= c3) && (b3 ~= c3) && (a3 > 0 && b3 > 0 && c3 > 0))

data= [a3,b3,c3];
ref2= data(1)
ref3=data(1)
ref1=data(1)
for j = 1:length(data)
%largest stroke length
if data(j)>ref2;
ref2=data(j);
end
end
for k = 1:length(data)
%smallest stroke length
if data(k)<ref3;
ref3=data(k);
end
end

for m = 1:length(data)
%stroke length in the middle
if ref3<data(m) & data(m)<ref2;
ref1=data(m);
end
end

if (ref2== a3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==b3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==c3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==a3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==b3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==c3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==a3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==b3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==c3)
app.Actuator3EditField.Value= "ref1" ;
end
% elseif((a3 == b3) || (a3 == c3) || (b3 == c3))
%check for rule C
else(((a3 == b3) || (a3 == c3) || (b3 == c3)) && (a3 > 0 && b3 > 0 && c3 > 0))

data_list= [d3,e3,f3];
ref2= data_list(1)
ref3=data_list(1)
ref1=data_list(1)
for n = 1:length(data_list)
%largest Building Dimension
if data_list(n)>ref2;
ref2=data_list(n);
end
end
for p = 1:length(data_list)
%smallest Building Dimension
if data_list(p)<ref3;
ref3=data_list(p);
end
end

for q = 1:length(data_list)
%Building Dimension in the middle
if ref3<data_list(q) & data_list(q)<ref2;
ref1=data_list(q);
end
end



if (ref2== d3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==e3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==f3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==d3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==e3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==f3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==d3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==e3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==f3)
app.Actuator3EditField.Value= "ref1" ;
end

%check for eqaul building dimentions
if(((d3 == e3) || (d3 == f3) || (e3 == f3)) && (d3 > 0 && e3 > 0 && f3 > 0))
app.OutputMessageEditField_2.Value ="Use channel assignment or config. tool";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

else
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

end
end
%should be out of main loop, independent
if(a3 == 0 ||b3 == 0 ||c3 == 0 ||d3 == 0 ||e3 == 0 ||f3 == 0 ||j3 == 0 ||k3 == 0 ||l3 == 0 )
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
end
end









share|improve this question









New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am writing a simple app using matlab app designer, My code works but I want to make it better. I have too many if else conditions. How can I avoid this? I use matlab app designer, I take 3 values and compare them again and again with different sets



 function buttonpush3Act(app, event)
a3= app.StrokeLengthmmEditField_13.Value;
b3=app.StrokeLengthmmEditField_12.Value;
c3= app.StrokeLengthmmEditField_11.Value;
d3=app.BuildingDimensionmmEditField_6.Value;
e3=app.BuildingDimensionmmEditField_5.Value;
f3=app.BuildingDimensionmmEditField_4.Value;
g3=app.orPreconfiguredrefnumEditField.Value;
h3=app.orPreconfiguredrefnumEditField_2.Value;
i3=app.orPreconfiguredrefnumEditField_3.Value;
j3=app.ActuatorTypeNumberEditField.Value;
k3=app.ActuatorTypeNumberEditField_2.Value;
l3=app.ActuatorTypeNumberEditField_3.Value;


%reset message field
app.OutputMessageEditField_2.Value= "";
% avoid missuse of the ´result´button
if(a3==0 && b3==0 && c3==0 && d3==0 && e3==0 && f3==0 && g3==0 && h3==0)
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value ='';

%check for pre configured actuators



elseif((j3== k3 == l3 || j3== k3 || j3== l3 || k3 == l3) && (j3 > 0 && k3 > 0 && l3 > 0)) %avoid having more than one LA40
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value =" ERROR2: Unsupported configuration";

%check if special actuators present
elseif((j3 == 40 && k3 ~= 40 && l3 ~= 40) || (j3 ~= 40 && k3 == 40 && l3 ~= 40) || (j3 ~= 40 && k3 ~= 40 && l3 == 40))
% a rotation to to catch la 40 and define it as ref4
dataLa40 = [j3,k3,l3];
ref4 = dataLa40(1)
for r= 1:length(dataLa40)
if dataLa40(r) == 40;
ref4 = dataLa40(r);
end
end
if (ref4 == dataLa40(1))
app.Actuator1EditField.Value = "ref4";
elseif(ref4 == dataLa40(2) )
app.Actuator2EditField.Value = "ref4";
else(ref4 == dataLa40(3))
app.Actuator3EditField.Value = "ref4";
end





% if act1== ref4 what if act2== ref4 what if act3== ref4 what

%check for rule D
elseif((a3 ~= b3) && (a3~= c3) && (b3 ~= c3) && (a3 > 0 && b3 > 0 && c3 > 0))

data= [a3,b3,c3];
ref2= data(1)
ref3=data(1)
ref1=data(1)
for j = 1:length(data)
%largest stroke length
if data(j)>ref2;
ref2=data(j);
end
end
for k = 1:length(data)
%smallest stroke length
if data(k)<ref3;
ref3=data(k);
end
end

for m = 1:length(data)
%stroke length in the middle
if ref3<data(m) & data(m)<ref2;
ref1=data(m);
end
end

if (ref2== a3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==b3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==c3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==a3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==b3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==c3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==a3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==b3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==c3)
app.Actuator3EditField.Value= "ref1" ;
end
% elseif((a3 == b3) || (a3 == c3) || (b3 == c3))
%check for rule C
else(((a3 == b3) || (a3 == c3) || (b3 == c3)) && (a3 > 0 && b3 > 0 && c3 > 0))

data_list= [d3,e3,f3];
ref2= data_list(1)
ref3=data_list(1)
ref1=data_list(1)
for n = 1:length(data_list)
%largest Building Dimension
if data_list(n)>ref2;
ref2=data_list(n);
end
end
for p = 1:length(data_list)
%smallest Building Dimension
if data_list(p)<ref3;
ref3=data_list(p);
end
end

for q = 1:length(data_list)
%Building Dimension in the middle
if ref3<data_list(q) & data_list(q)<ref2;
ref1=data_list(q);
end
end



if (ref2== d3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==e3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==f3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==d3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==e3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==f3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==d3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==e3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==f3)
app.Actuator3EditField.Value= "ref1" ;
end

%check for eqaul building dimentions
if(((d3 == e3) || (d3 == f3) || (e3 == f3)) && (d3 > 0 && e3 > 0 && f3 > 0))
app.OutputMessageEditField_2.Value ="Use channel assignment or config. tool";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

else
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

end
end
%should be out of main loop, independent
if(a3 == 0 ||b3 == 0 ||c3 == 0 ||d3 == 0 ||e3 == 0 ||f3 == 0 ||j3 == 0 ||k3 == 0 ||l3 == 0 )
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
end
end









share|improve this question









New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am writing a simple app using matlab app designer, My code works but I want to make it better. I have too many if else conditions. How can I avoid this? I use matlab app designer, I take 3 values and compare them again and again with different sets



 function buttonpush3Act(app, event)
a3= app.StrokeLengthmmEditField_13.Value;
b3=app.StrokeLengthmmEditField_12.Value;
c3= app.StrokeLengthmmEditField_11.Value;
d3=app.BuildingDimensionmmEditField_6.Value;
e3=app.BuildingDimensionmmEditField_5.Value;
f3=app.BuildingDimensionmmEditField_4.Value;
g3=app.orPreconfiguredrefnumEditField.Value;
h3=app.orPreconfiguredrefnumEditField_2.Value;
i3=app.orPreconfiguredrefnumEditField_3.Value;
j3=app.ActuatorTypeNumberEditField.Value;
k3=app.ActuatorTypeNumberEditField_2.Value;
l3=app.ActuatorTypeNumberEditField_3.Value;


%reset message field
app.OutputMessageEditField_2.Value= "";
% avoid missuse of the ´result´button
if(a3==0 && b3==0 && c3==0 && d3==0 && e3==0 && f3==0 && g3==0 && h3==0)
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value ='';

%check for pre configured actuators



elseif((j3== k3 == l3 || j3== k3 || j3== l3 || k3 == l3) && (j3 > 0 && k3 > 0 && l3 > 0)) %avoid having more than one LA40
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
app.OutputMessageEditField_2.Value =" ERROR2: Unsupported configuration";

%check if special actuators present
elseif((j3 == 40 && k3 ~= 40 && l3 ~= 40) || (j3 ~= 40 && k3 == 40 && l3 ~= 40) || (j3 ~= 40 && k3 ~= 40 && l3 == 40))
% a rotation to to catch la 40 and define it as ref4
dataLa40 = [j3,k3,l3];
ref4 = dataLa40(1)
for r= 1:length(dataLa40)
if dataLa40(r) == 40;
ref4 = dataLa40(r);
end
end
if (ref4 == dataLa40(1))
app.Actuator1EditField.Value = "ref4";
elseif(ref4 == dataLa40(2) )
app.Actuator2EditField.Value = "ref4";
else(ref4 == dataLa40(3))
app.Actuator3EditField.Value = "ref4";
end





% if act1== ref4 what if act2== ref4 what if act3== ref4 what

%check for rule D
elseif((a3 ~= b3) && (a3~= c3) && (b3 ~= c3) && (a3 > 0 && b3 > 0 && c3 > 0))

data= [a3,b3,c3];
ref2= data(1)
ref3=data(1)
ref1=data(1)
for j = 1:length(data)
%largest stroke length
if data(j)>ref2;
ref2=data(j);
end
end
for k = 1:length(data)
%smallest stroke length
if data(k)<ref3;
ref3=data(k);
end
end

for m = 1:length(data)
%stroke length in the middle
if ref3<data(m) & data(m)<ref2;
ref1=data(m);
end
end

if (ref2== a3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==b3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==c3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==a3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==b3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==c3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==a3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==b3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==c3)
app.Actuator3EditField.Value= "ref1" ;
end
% elseif((a3 == b3) || (a3 == c3) || (b3 == c3))
%check for rule C
else(((a3 == b3) || (a3 == c3) || (b3 == c3)) && (a3 > 0 && b3 > 0 && c3 > 0))

data_list= [d3,e3,f3];
ref2= data_list(1)
ref3=data_list(1)
ref1=data_list(1)
for n = 1:length(data_list)
%largest Building Dimension
if data_list(n)>ref2;
ref2=data_list(n);
end
end
for p = 1:length(data_list)
%smallest Building Dimension
if data_list(p)<ref3;
ref3=data_list(p);
end
end

for q = 1:length(data_list)
%Building Dimension in the middle
if ref3<data_list(q) & data_list(q)<ref2;
ref1=data_list(q);
end
end



if (ref2== d3)
app.Actuator1EditField.Value= "ref2" ;
elseif(ref2==e3)
app.Actuator2EditField.Value= "ref2" ;
else(ref2==f3)
app.Actuator3EditField.Value= "ref2" ;
end
if(ref3==d3)
app.Actuator1EditField.Value= "ref3" ;
elseif(ref3==e3)
app.Actuator2EditField.Value= "ref3" ;
else(ref3==f3)
app.Actuator3EditField.Value= "ref3" ;
end
if(ref1==d3)
app.Actuator1EditField.Value= "ref1" ;
elseif(ref1==e3)
app.Actuator2EditField.Value= "ref1" ;
else(ref1==f3)
app.Actuator3EditField.Value= "ref1" ;
end

%check for eqaul building dimentions
if(((d3 == e3) || (d3 == f3) || (e3 == f3)) && (d3 > 0 && e3 > 0 && f3 > 0))
app.OutputMessageEditField_2.Value ="Use channel assignment or config. tool";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

else
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';

end
end
%should be out of main loop, independent
if(a3 == 0 ||b3 == 0 ||c3 == 0 ||d3 == 0 ||e3 == 0 ||f3 == 0 ||j3 == 0 ||k3 == 0 ||l3 == 0 )
app.OutputMessageEditField_2.Value ="ERROR2; Fill the required fields";
app.Actuator1EditField.Value= '';
app.Actuator2EditField.Value= '';
app.Actuator3EditField.Value ='';
end
end






matlab






share|improve this question









New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 46 mins ago





















New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Gombakka

11




11




New contributor




Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Gombakka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 hours ago


















  • Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
    – Toby Speight
    2 hours ago
















Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
2 hours ago




Welcome to Code Review! This question is incomplete. To help reviewers give you better answers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier it will be for reviewers to help you. The current title states your concerns about the code; it needs an edit to simply state the task; see How to get the best value out of Code Review: Asking Questions for guidance on writing good question titles.
– Toby Speight
2 hours ago















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Gombakka is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207537%2fhow-to-avoid-too-many-if-else-statements%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Gombakka is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Gombakka is a new contributor. Be nice, and check out our Code of Conduct.













Gombakka is a new contributor. Be nice, and check out our Code of Conduct.












Gombakka is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207537%2fhow-to-avoid-too-many-if-else-statements%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Terni

A new problem with tex4ht and tikz

Sun Ra