필터 지우기
필터 지우기

how to correct this index error ?

조회 수: 1 (최근 30일)
Dhines
Dhines 2013년 1월 9일
su=4;
sv=4;
fh=[1 2 3 4; 2 3 4 5 ; 5 6 7 8 ; 1 2 3 5];
for i=-4:4
for j=-4:4
a(i,j)=1;
for u=1:su-2
for v=1:sv
if (fh(u,v)==i && fh(u+1,v)==j)
dell=1;
else
dell=0;
end
a(i,j)=a(i,j)+dell;
end
end
end
end
..when i run this code i got this error..
??? Attempted to access a(-4,-4); index must be a positive integer or logical.
Error in ==> testit at 6
a(i,j)=1;
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2013년 1월 9일
see this answer
Jan
Jan 2013년 1월 9일
Please, prasana, use meaningful tags. Almost all questions in this forum concern Matlab code.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2013년 1월 9일
You are working with Matlab for at least 3 month. It is time to read the Getting Started chapters to find out, that indices must be positive integers. Therefore you cannot access the element a(-4, -4). This seems to be a trivial solution:
for i = 1:9
for j = 1:9

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by