I am very new to matlab and am having syntax errors. Index in position 2 is invalid. Array indices must be positive integers or logical values. Error in tension (line 36) temp= (Be/N).*( log2( 1 + ( colony( j,d(len1)+r ).*(CG1)^2)/(sigma*Be)/N));
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
siva sagar
am 21 Sep. 2019
Kommentiert: siva sagar
am 14 Okt. 2019
function [out R]=tension(colony)
global P_total K gamma H N No B R PTerrh2 PTx1 PTx2 PTx PT1 PT2 R1 R2 R3 I1 I2 I3 r1 r2 r2 r
global PTerrh1 PTerrh loss Distance FoodNumber CG1 CG2 D d Pl_eRU Pl_RU P_total K gamma H N No B R M Be rowm deltam P_FA P_FS P_BS P_RS_eRRH P_RS_RRH PTX_eRRH PTX_RRH sigma PT
for j=1:size(colony,1)
a=zeros(1,D);
for i=1:5
a=find(round(colony(j,1:N))==i);
len=size(a,2);
b=(20*i)+1;
c=(20)*(i+1);
r=b+200;
d=zeros(1,D);
for h=1:len
d=zeros(1,D);
d=find((round(colony(j,b:c)))==a(h));
len1=size(d,2);
temp=zeros(1,len1);
I1=zeros(1,len1);
CG1=[];
for l=1:len1
% colony( j,a(l)+N );
%temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( 1,1+ K*( a(l)-1 ) ) ).^2)./(No * B/N) ) ) ) ;
%% temp(1,l)= (1/N).* ( log2( 1 + ( colony( j,a(l)+64 ).*(( H( i,a(l) ) )))./(No * B/N) ) );
% temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l)+64 ).*(( H( i,a(l) ) ))) ) ) ;
% temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( i,a(l) ) ))./(No * B/N) ) ) ) ;
% %temp1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( i,a(l) ) )) ) ) ) ;
% loss = 128.1 + 37.6*(log10(Distance(j,len1(i))));
CG1(l)= 10^(-((128.1 + 37.6*(log10(Distance(j,d(h)))))/10));
temp(l)= (Be/N).*( log2( 1 + ( colony( j,d(len1)+r ).*(CG1)^2)/(sigma*Be)/N));
I1(l)= colony( j,d(len1)+r );
r(1)=rowm;
end
R1(h)= sum(temp);
I2(h)=sum(I1);
r1(h)=sum(r);
r=[];
I1=[];
end
R2(i)=sum(R1);
Ip1=sum(I2);
r2(i)=sum(r1);
R1=[];
I2=[];
r1=[];
end
0 Kommentare
Akzeptierte Antwort
Naveen Venkata Krishnan
am 10 Okt. 2019
Hello siva,
You have missed some ends. To remove the syntax errors try using the below code, but with respect to logic and variables I think you need to work it out
function [out R]=tension(colony)
global P_total K gamma H N No B R PTerrh2 PTx1 PTx2 PTx PT1 PT2 R1 R2 R3 I1 I2 I3 r1 r2 r2 r
global PTerrh1 PTerrh loss Distance FoodNumber CG1 CG2 D d Pl_eRU Pl_RU P_total K gamma H N No B R M Be rowm deltam P_FA P_FS P_BS P_RS_eRRH P_RS_RRH PTX_eRRH PTX_RRH sigma PT
for j=1:size(colony,1)
a=zeros(1,D);
for i=1:5
a=find(round(colony(j,1:N))==i);
len=size(a,2);
b=(20*i)+1;
c=(20)*(i+1);
r=b+200;
d=zeros(1,D);
for h=1:len
d=zeros(1,D);
d=find((round(colony(j,b:c)))==a(h));
len1=size(d,2);
temp=zeros(1,len1);
I1=zeros(1,len1);
CG1=[];
for l=1:len1
% colony( j,a(l)+N );
%temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( 1,1+ K*( a(l)-1 ) ) ).^2)./(No * B/N) ) ) ) ;
%% temp(1,l)= (1/N).* ( log2( 1 + ( colony( j,a(l)+64 ).*(( H( i,a(l) ) )))./(No * B/N) ) );
% temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l)+64 ).*(( H( i,a(l) ) ))) ) ) ;
% temp(1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( i,a(l) ) ))./(No * B/N) ) ) ) ;
% %temp1,l)= (1/N).* ( log2( 1 + ( p( j,a(l) ).*(( H( i,a(l) ) )) ) ) ) ;
% loss = 128.1 + 37.6*(log10(Distance(j,len1(i))));
CG1(l)= 10^(-((128.1 + 37.6*(log10(Distance(j,d(h)))))/10));
temp(l)= (Be/N).*( log2( 1 + ( colony( j,d(len1)+r ).*(CG1)^2)/(sigma*Be)/N));
I1(l)= colony( j,d(len1)+r );
r(1)=rowm;
end
R1(h)= sum(temp);
I2(h)=sum(I1);
r1(h)=sum(r);
r=[];
I1=[];
end
R2(i)=sum(R1);
Ip1=sum(I2);
r2(i)=sum(r1);
end
R1=[];
I2=[];
r1=[];
end
end
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!