Problem with code-beginner

1 回表示 (過去 30 日間)
Bianca Brisc
Bianca Brisc 2021 年 6 月 15 日
編集済み: David Hill 2021 年 6 月 15 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by