problem in matlab code

조회 수: 1 (최근 30일)
brahmi ibtissem
brahmi ibtissem 2019년 8월 4일
댓글: Walter Roberson 2019년 8월 6일
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 ) ;
>>

답변 (2개)

Image Analyst
Image Analyst 2019년 8월 4일
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
Guillaume
Guillaume 2019년 8월 5일
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 2019년 8월 5일
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.

댓글을 달려면 로그인하십시오.


KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 4일
  댓글 수: 7
brahmi ibtissem
brahmi ibtissem 2019년 8월 6일
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 2019년 8월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by