Struct contents reference from a non-struct array object error

Hi,
In the following code, the mentioned error is announced after a iteration. What is the reason for this that there is no error in the first iteration and why it is wrong in the second iteration
error: Struct contents reference from a non-struct array object
f=[pop.cost];
f=1./f;
f=f./sum(f);
f=cumsum(f);
%Crossover
pop2=repmat(empty_individual,Nc/2,2);
for i=1:Nc/2
i1=find(rand<=f,1,'first');
i2=find(rand<=f,1,'first');
%Select parent
P1=(pop(i1));
P2=(pop(i2));
Ch_1.beta=(R1.*P1.beta)+(R2.*P2.beta);
Ch_2.beta=(R2.*P1.beta)+(R1.*P2.beta);
Ch_1.sigma=(R1.*P1.sigma)+(R2.*P2.sigma);
Ch_2.sigma=(R2.*P1.sigma)+(R1.*P2.sigma);
Ch_1.ro=(R1.*P1.ro)+(R2.*P2.ro);
Ch_2.ro=(R2.*P1.ro)+(R1.*P2.ro);

Réponses (0)

Catégories

En savoir plus sur MATLAB 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!

Translated by