Undefined function 'count' for input arguments of type 'logical'.
이전 댓글 표시
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.
댓글 수: 1
I can't follow what you're trying to do here, sorry.
The error is that count is a builtin string function that returns the number instances of a given STRING pattern within another string and you've defined D, T, L all as integers, not character plus you have only a single argument into count that is a logical expression, not a string and rather than two character arguments needed of the string and pattern string to match/count.
Also since L=1:26 and is never modified, nothing is going to happen inside the loops that's any different than without any loop; there's nothing referenced inside the loop that isn't invariant for the loop indices.
NB
L==1 will return a logical vector of T/F but since L is fixed it will be T for the first position and F everywhere else. Also look up how IF works in Matlab; the condition will be T iff all elements in the quantity are T; hence that test even if it were coded correctly would never be T and the IF branch never executed.
Show us a small test case of inputs and expected outputs to help with the verbal explanation...
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!