MATLAB: Subscript indices must either be real positive integers or logicals.

errorfor loopimage processingMATLABsumvideo processing

I've been getting this error when trying to sum a column: "Subscript indices must either be real positive integers or logicals." and my matrix is uint8 and its values are all zero and it happens starting with the first cell so its no isolated incident, whats the problem? there's my code: bw is a grayscale image from a video with black borders which I'm trying to delete. for the first image it worked but for the second it received an error.
for col=1:size(bw,2)
coloumn = sum(uint8(bw(:,col)));
if coloumn>0
if col==1
maxMinCol2 = 1;
else
maxMinCol2 = col-1;
break
end
end
end
ps: I know there's already other answered pages about his error but I couldnt find this specific circumstance of the error.
thanks in advance 🙂 .

Best Answer

You have a variable named sum. Clear it:
clear sum
Related Question