Problem with code-beginner

1 次查看(过去 30 天)
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 个评论
dpb
dpb 2021-6-15
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???

请先登录,再进行评论。

采纳的回答

David Hill
David Hill 2021-6-15
编辑:David Hill 2021-6-15
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by