필터 지우기
필터 지우기

Attempted to access b(0,:); index must be a positive integer or logical.

조회 수: 1 (최근 30일)
Andy
Andy 2013년 4월 17일
for k=1:14;
[col,row]=size(b);
prj=zeros(col,1);
for i=1:col
for j=1:row
if b(i,j)==0
prj(i)=prj(i)+1;
end
end
end
rup = 0;rdw = 0;
for i = 1:col
if prj(i)==0 && prj(i+1)>=1
rup = i;
end
if prj(i)>=1 && prj(i+1)==0
rdw = i+1;
break
end
end
range = rdw-rup;
ab = ones(range,row);
for i= rup:rdw
ab(i-rup+1,:) = b(i,:);
b(i,:)=1;
end
figure;imshow(ab);
k=k+1;
end
I have some problems with the above code and I keep getting the "attempt to access" error.
The size of matrix b is [3508 2480].
Can anybody shed some like as to fix it?
I get the following error:
Attempted to access prj(3509); index out of bounds
because numel(prj)=3508.
Error in main (line 67)
if prj(i)==0 && prj(i+1)>=1

답변 (2개)

Walter Roberson
Walter Roberson 2013년 4월 17일
You start with rup = 0. You then have a loop that conditionally assigns a different value to rup. You then loop "i" starting from rup. But suppose the conditions of the conditional assignment were never true: then rup would still be 0, and you would be looping starting from 0.

Andy
Andy 2013년 4월 17일
Thank you for your explanation. It seems really complicated to understand. Are there anything that I can change to make it work? Like plus 1 somewhere? Thanks!
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 4월 17일
You need to decide what you want to do if your "for i = 1:col" loop does not find any matches.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by