Attempted to access b(0,:); index must be a positive integer or logical.
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Walter Roberson
on 17 Apr 2013
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.
0 Comments
Andy
on 17 Apr 2013
1 Comment
Walter Roberson
on 17 Apr 2013
You need to decide what you want to do if your "for i = 1:col" loop does not find any matches.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!