Question with for loop 'Index in position 1 exceeds array bounds (must not exceed 9)'

1 回表示 (過去 30 日間)
Hi all,
I don't know how to make sure index i not exceed the array bound in this case (since lats is a 9x13 matrix, NumCenPts is actually the matrix's number of columns and depends on the situation number of rounds can be larger then number of columns and vice versa). need_to_modify_code.m is attached below
NumCenPts = 13;
load('need_to_modify_code');
V=10;
for i=1:length(lats)-1
for j=1:NumCenPts
%------------------------------------------------------
%Defining arcs and cost for going straight
%------------------------------------------------------
arcStraight(i,j)=distance('rh',lats(i,j), lons(i,j),lats(i+1,j),lons(i+1,j),referenceEllipsoid(7030));
%Defining arcs and cost for going right
%------------------------------------------------------
if j<NumCenPts
arcRight(i,j)=distance('rh',lats(i,j),lons(i,j), lats(i+1,j+1),lons(i+1,j+1),referenceEllipsoid(7030));
end
%-------------------------------------------------------
%Defining arcs and costs for going left
%------------------------------------------------------
if j>1
arcLeft(i,j)=distance('rh',lats(i,j),lons(i,j), lats(i+1,j-1),lons(i+1,j-1),referenceEllipsoid(7030));
end
end
end
Thank you for your time,
Sincerely,

採用された回答

per isakson
per isakson 2019 年 6 月 4 日
編集済み: per isakson 2019 年 6 月 4 日
Line 9
arcStraight(ii,jj)=distance('rh',lats(ii,jj), lons(ii,jj),lats(ii+1,jj),lons(ii+1,jj),referenceEllipsoid(7030));
contains lats(ii+1,jj) and lons(ii+1,jj), which triggers the error when ii==9, since the size of lats and lons are <9x13>. 9+1 is 10 which is "outside" lons

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by