Why this error happened when i run genetic algorithm?
Afficher commentaires plus anciens
when i run this function in genetic algorithm in optimization tool box this error occur
- Attempt to execute SCRIPT ga as a function:
function [ F ] = FF( A )
% A =[ 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1
% 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1
% 1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 1
% 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 1
% 0 1 1 1 1 0 1 0 0 1 1 1 1 1 0 1
% 0 0 1 1 0 1 1 0 1 1 1 0 1 0 0 1
% 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 1
% 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
% 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
% 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 ];
% input ' A = ' ;
[n,m]=size(A);
B=(m+repmat(1:m,n,1)-A.*cumsum(A,2)).*A;
for k=1:n
a=B(k,B(k,:)~=0);
[~,~,kk]=unique(a);
row1{k,1}=accumarray(kk,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %c= represent sum of rows
c1 = cellfun(@sum, row1);
Z1 = randi([0 1], n,m);
B1=(m+repmat(1:m,n,1)-Z1.*cumsum(Z1,2)).*Z1;
for k=1:n
a=B1(k,B1(k,:)~=0);
[~,~,kk]=unique(a);
row2{k,1}=accumarray(kk,1);
end
d1 = cellfun(@sum, row2);
x1= abs( c1-d1);
% F(X1)
X1 = sum(x1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Find F(X2)
C=(n+repmat(1:n,m,1)-A'.*cumsum(A',2)).*A';
for k=1:m
a=C(k,C(k,:)~=0);
[~,~,kk]=unique(a);
col1{k,1}=accumarray(kk,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% x represnt sum of column
c2 = cellfun(@sum, col1);
% x = d.';
Z2 = randi([0 1], n,m);
C2=(n+repmat(1:n,m,1)-Z2'.*cumsum(Z2',2)).*Z2';
for k=1:m
a=C2(k,C2(k,:)~=0);
[~,~,kk]=unique(a);
col1{k,1}=accumarray(kk,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% x represnt sum of column
c3 = cellfun(@sum, col1);
c4 = abs (c3-c2);
X2 = sum(c4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Find F(X3)
idx = A~=1;
r = sum(idx,2);
Z3 = randi([0 1], n,m);
idx1 = Z3~=1;
r5 = sum(idx1,2);
r6 = abs (r-r5);
X3= sum(r6);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Find F(X4)
idx = A~=1;
c = sum(idx,1);
Z4 = randi([0 1], n,m);
idx1 = Z4~=1;
c5 = sum(idx1,1);
c6 = abs(c-c5);
X4= sum(c6);
F = X1+X2+X3+X4;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Genetic Algorithm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!