Undefined operator '==' for input arguments of type 'cell'?
古いコメントを表示
i got an error
Undefined operator '==' for input arguments of type 'cell'.
Error in GeneratePopulation (line 143)
pt=find(p1==1); %cycle value utk p1
what can i do to fix it?
%% parent selection
cp=0.4; % Crossover Percentage
np=2*round(cp*r/2); % Number of Offsprings (Parents)
% np=cp*r
valp=np/2;
v=valp;
n1=length(RS(:,1));
PP=RS([1:v,n1-v+1:end],3:end);
P=cell(1,np); % preallocate
for i=1:np
P{i} = PP(i,:);
end
%celldisp(P);
%vertcat(P{:}); % double array
%% CYCLE CROSSOVER
szcld = size(P,2); % p
n2=length(P(:,1));
c1=zeros(1,szcld);
c2=zeros(1,szcld);
p1= P(1:v);
p2= P(1:n2-v+1:end);
pt=find(p1==1); %cycle value utk p1
for i=1:P
while (c1(pt)==0)
c1(pt)=p1(pt);
pt=find(p1==p2(pt));
end
left=find(c1==0);
c1(left)=p2(left)
pt=find(p4==1); %cycle value utk p1
while (c2(pt)==0)
c2(pt)=p4(pt);
pt=find(p2==p1(pt));
end
left=find(c2==0);
c2(left)=p1(left);
end
回答 (1 件)
madhan ravi
2019 年 1 月 7 日
P=vertcat(P{:}); % double array %% uncomment this line
10 件のコメント
Walter Roberson
2019 年 1 月 7 日
If you do that then you might as well use PP instead of PP since PP is in matrix form and for some reason is being deliberately broken out into rows.
madhan ravi
2019 年 1 月 7 日
True sir Walter completely missed that part , OP has to clarify further more and indeed he needs to provide the missing datas to run the code.
Walter Roberson
2019 年 1 月 7 日
編集済み: Walter Roberson
2019 年 1 月 7 日
left is not a variable in the code you posted so we have no idea what it is set to.
sharifah shuthairah syed abdullah
2019 年 1 月 7 日
Walter Roberson
2019 年 1 月 7 日
Your PP matrix is 2d. Exactly what part of the 2d array should be tested for value equal 1?
sharifah shuthairah syed abdullah
2019 年 1 月 8 日
Walter Roberson
2019 年 1 月 8 日
Why result1 and result4 ? You look like you are doing a traveling salesman problem in which every row is a permutation of 1:12, so all of the rows will contain a 1 . I do not understand what you expect
pt=find(p1==1);
to return?
sharifah shuthairah syed abdullah
2019 年 1 月 8 日
Walter Roberson
2019 年 1 月 8 日
So you want to find all the linear indices in p1 at which the value is 1? Not the column number in each row?
sharifah shuthairah syed abdullah
2019 年 1 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!