problem in matlab code

1 view (last 30 days)
brahmi ibtissem
brahmi ibtissem on 4 Aug 2019
Commented: Walter Roberson on 6 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 ) ;
>>

Answers (2)

Image Analyst
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
  3 Comments
Guillaume
Guillaume on 5 Aug 2019
The problem is still the same, population.Chromosomes(indx(1)).fitness is a vector, a matrix, or is empty. I.E: it's not just one element. And you try to assign it to a single element of a variable.
Image Analyst
Image Analyst on 5 Aug 2019
brahmi, why did you not put in the whos statements like I specifically asked you for? You're just delaying an answer by not doing the things we suggest.

Sign in to comment.


KALYAN ACHARJYA
KALYAN ACHARJYA on 4 Aug 2019
  7 Comments
brahmi ibtissem
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
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.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!