Asked by brahmi ibtissem
on 4 Aug 2019

Hello,

Please how i can solve this problem in my Matlab code:

In an assignment A(:) = B, the number of elements in A and B must be the same.

Error in ObjectiveFunction (line 73)

throughputCR(i)= throughputCR(i)+W*log2(1+ SinrCR(i,j));

Error in PSO (line 94)

Swarm.Particles(k).O = fobj(currentX);

Error in main (line 54)

[ GBEST , cgcurve ] = PSO( noPa , maxItera , visFlaga ) ;

>>

Answer by Image Analyst
on 4 Aug 2019

W is probably a vector and so the entire right hand side is a vector. You can't stuff, say, 100 elements into throughputCR(i) which is just a single element.

If you put these lines before the bad line, what does it report in the command window?

whos throughputCR

whos W

whos SinrCR

brahmi ibtissem
on 5 Aug 2019

hello, i still have this problem in my matlab code:

26.9763 0 0 0 0

12.6823 0 0 0 0

g =

1

Generation #1

In an assignment A(:) = B, the number of elements in A and B must be the same.

Error in GeneticAlgorithm (line 11)

cgcurve(g) = population.Chromosomes(indx(1)).fitness;

Error in Main (line 36)

[BestChrom] = GeneticAlgorithm (M , N, MaxGen , Pc, Pm , Er , Problem.obj , visualization)

>>

Guillaume
on 5 Aug 2019

Image Analyst
on 5 Aug 2019

Sign in to comment.

Answer by KALYAN ACHARJYA
on 4 Aug 2019

A= B;

Walter Roberson
on 5 Aug 2019

Show us the code for ObjectiveFunction

brahmi ibtissem
on 6 Aug 2019

this is the code of the objectivefunctioon

% *************************************************************************************************************************************************

function [fitness_value] = Sphere( X )

% *************************************************************************************************************************************************

global C;

global V;

global RB;

global Noise

global W;

global Pcellular;

global binv;

global Pv;

global PositionsBS;

global PositionsC;

global PositionsV;

constraintSatified=true;

Pcellular=23*X(:,:,1);

Pv=X(:,:,1);

%binv=X(:,:,1);

binv=zeros(V,RB);;

global binc;

binc=zeros(C, RB);

for i=1:C

for j=1:RB

if i==j

binc(i,j)=1;

end

end

end

%matrix user in line, column RB

SINRcth=0;

SINRvth=0;

%calculate the throughput and the interferences of a eh user type

throughputC=zeros(C);

SinrC=zeros(C,RB);

for i=1:C

Icv=0;

for j=1:RB

if binc(i,j)==1

for v=1:V

if binv(v,j)==1

Icv=Icv+Pv(v,j)*calculate_gain(PositionsBS(1),PositionsBS(2), PositionsV(v,1),PositionsV(v,2) );

end

end

SinrC(i,j)=Pcellular(i,j)*calculate_gain(PositionsBS(1),PositionsBS(2), PositionsC(i,1),PositionsC(i,2) )/(Icv+Noise);

throughputC(i)= throughputC(i)+W*log2(1+ SinrC(i,j));

plot( throughputC(i));

end

end

if throughputC(i)<SINRcth

constraintSatified=false;

end

end

throughputV=zeros(V);

SinrV=zeros(V,RB);

for v=1:V

Ivc=0;

for j=1:RB

if binv(i,j)==1

for c=1:C

if binc(c,j)==1

Ivc=Ivc+Pcellular(i,j)*calculate_gain(PositionsC(i,1),PositionsC(i,2), PositionsV(v,1),PositionsV(v,2) );

end

end

SinrV(v,j)=Pv(v,j)*calculate_gain(PositionsV(v,1),PositionsV(v,2),PositionsC(c,1),PositionsC(c,2) )/(Ivc+Noise);

throughputV(v)= throughputV(v)+W*log2(1+ SinrV(v,j));

disp( throughputV(v));

end

end

if throughputV(v)< SINRvth

constraintSatified=false;

end

end

if constraintSatified==false

fitness_value = 0;

else

a=sum(throughputV);

b=sum(throughputC);

fitness_value=max(a,b);

disp(fitness_value);

end

end

Walter Roberson
on 6 Aug 2019

global W;

You do not show us where you initialized W. W might be its default value for a global variable, which is to say it might be empty.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.