Problem with code-beginner

1 visualizzazione (ultimi 30 giorni)
Bianca Brisc
Bianca Brisc il 15 Giu 2021
Modificato: David Hill il 15 Giu 2021
I have this code, and I receive the following error:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in antennas3sector_final (line 21)
distances(site,r,c) = sqrt((x(r,c,site)+xshift(site)).^2+(y(r,c,site)+yshift(site)).^2);
Can you please help me ? Thank you.
distances = zeros(length(xx),length(yy),NumberOfSites);
for site = 1:NumberOfSites
for r = 1:length(distances)
for c = 1:length(distances)
xshift(site) = isd*sind(AngleDistance*(site-1));
yshift(site) = isd*cosd(AngleDistance*(site-1));
distances(site,r,c) = sqrt((x(r,c,site)+xshift(site)).^2+(y(r,c,site)+yshift(site)).^2);
end;
end;
end;
  1 Commento
dpb
dpb il 15 Giu 2021
for site = 1:NumberOfSites
for r = 1:length(distances)
for c = 1:length(distances)
xshift(site) = isd*sind(AngleDistance*(site-1));
...
What is (site-1) when site==1 the first pass thru the loop???

Accedi per commentare.

Risposta accettata

David Hill
David Hill il 15 Giu 2021
Modificato: David Hill il 15 Giu 2021
distances = zeros(length(xx),length(yy),NumberOfSites);
xshift = isd*sind(AngleDistance*((1:NumberOfSites)-1));%assume isd and AngleDistance is a constant
yshift = isd*cosd(AngleDistance*((1:NumberOfSites)-1));%calculate outside loop
for site = 1:NumberOfSites
distances(:,:,site) = sqrt((x(:,:,site)+xshift(site)).^2+(y(:,:,site)+yshift(site)).^2);
end

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by