MATLAB: Undefined function ‘count’ for input arguments of type ‘logical’.

constraintfitness functiongagenetic algorithmtimetabling

Im trying to code my fitness function with just one constraint inside that m.file but i run into and error that says
"Undefined function 'count' for input arguments of type 'logical'.
Error in my_fun (line 22)
if count (L == 1) == 1; "
I don't really how to fix it. the following is the piece of code.
function y = my_fun(c1)
w1 = 0.8;
% w2 = 0.8;
% w3 = 0.8;
% y = w1*x1 + w2*x2 + w3*x3;
X=xlsread('Dataset.xlsx');
% Xout=X(:,end);
D = 1:5;
T = 1:9;
L = 1:26;
chromosome = [D T L];
%Constraint 1
for DateID = D
for TimeID = T
if count (L == 1) == 1;
c1 = 0;
else
c1 = 1;
end
end
end
y = w1*c1;
In here, im trying to define my chromosome in the form of [D T L] and also assigning the ID in my dataset to be the genotype. In constraint 1, im trying to find if the L have violated the constraints and it gives the value 1, and if not then 0.
PLease advice. thanks.

Best Answer

Perhaps you want sum() to count the number of 1's in the array? Like this?
if sum(L == 1) == 1
By the way, no semicolon is needed at the end of an if statement.
Please attach 'Dataset.xlsx' if you need more help.
By the way, why do you pass in c1 to the function when you just ignore it by overwriting it?