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

1 次查看(过去 30 天)
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!

类别

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