Index in position 2 exceeds array bounds
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a problem with this, I dont know whats wrong
n=4;
r= 0.012;
pos = [0 0; 0 0.5; 0.5 0.5; 0.5 0]
a = zeros(1,n)
i=1
while( i<=n)
for(j=1:1:n-1)
for(k=1:1:n-1)
x = pos(k+1,1)-pos(1,j) %%------> I have the problem here
It says "Index in position 2 exceeds array bounds"
댓글 수: 0
답변 (2개)
KSSV
2020년 2월 18일
You size of pos is 4x2....you are trying to accessing third coulmn from pos....where as it has only two columns..so obviously you will end up with error.
댓글 수: 0
Hyeokjin Jho
2020년 2월 18일
Since n = 4, for(j=1:1:n-1) will make j from 1 to 3.
However pos is 4x2 matrix. When j is 3, pos(1,j) refers outside of the matrix boundary.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!