How to solve array indices error?

1 view (last 30 days)
gp
gp on 26 Dec 2021
Answered: James Tursa on 26 Dec 2021
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in FWA (line 53)
sp = distance1(x1,y1,z1,dx,dyv(i),dz); % incident distance
CODE:
f = 2.4*(10^9);
c = 3*(10^8);
lambda = c/f; % wavelength
beta = 2*pi/lambda;
ft = 0.3048; % 1 foot = 0.3048m
in = 2.54/100; % 1 inch = 2.54cm
erw = 2; % Permiability for wall
sigw = 0.0001;
u2 = 1;
erg = 7;
sigg = 0.0001;
constant = (lambda/4/pi)^2;
factor = lambda/4/pi;
% define the coordinates
x1 = 0*ft;
y1 = 0;
z1 = 6*ft+10*in;
x2 = 0*ft;
y2 = 10;
z2 = 6*ft+10*in;
y2v = (y2:1:85+7)*ft;
distance1=sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2);
%d3 = distance1(x1,y1,z1,x2,y2,z2);
Ed = (1./distance1).*exp(-j*beta*distance1).*factor; % formula given for direct ray of electric field
Edf = 20*log10(abs(Ed)); % direct ray alone
x3 = 20*ft;
y3 = 0;
z3 = 6*ft+10*in;
% knife edge wall
dtr = pi/180; % degree to rad
rtd = 1/dtr; % rad to degree
n = 2;
btd = 90; % incident angle
dx = 10*ft;
dz = z1;
dy1 = 0.48;
dyv = dy1:0.635:dy1+(0.635*48);
pphid = [];
ets = [];
aets = [];
for i= 1:size(dyv,2)
sp = distance1(x1,y1,z1,dx,dyv(i),dz); % incident distance
s = distance1(dx,dyv(i),dz,x2,y2v,dz); % observation distance
phipd = atand(dx./dyv(i)); % incident angle
cc = exp(-sqrt(-1)*beta*sp)/sp;
A = sqrt(sp./(s.*(sp+s))); % spreading factor (spherical)
L = ((s.*sp*sin(btd*dtr)^2)./(s+sp))/lambda; % distance parameter (spherical)
pf = exp(-sqrt(-1)*beta*s); % phase factor
for j = 1:size(y2v,2)
ny2v = y2v(j);
if ny2v < dyv(i)
phid = atand(dx./(dyv(i)-ny2v)); % observation angle
elseif ny2v > dyv(i)
phid = 90+atand((ny2v-dyv(i))./dx);
end
[pphid] = [pphid,phid];
end
for k = 1:size(y2v,2)
[ds,dh,D] = wdcpub(L(k),pphid(k),phid,btd,n);
edfrs = cc*A(k)*pf(k)*ds*0.5*sqrt(lambda)*factor;
ets = [ets,edfrs];
end
aets = [aets;ets];
pphid = [];
ets = [];
end
edif = sum(aets);
edifr = 20*log10(abs(edif));

Answers (1)

James Tursa
James Tursa on 26 Dec 2021
x1 = 0*ft;
:
distance1=sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2);
:
sp = distance1(x1,y1,z1,dx,dyv(i),dz); % incident distance
x1 is zero, distance1 is a scalar, hence the error. What is that last line supposed to do? Is distance1 supposed to be a function?

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!