Question with for loop 'Index in position 1 exceeds array bounds (must not exceed 9)'
Afficher commentaires plus anciens
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,
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!