Subscript indices must either be real positive integers or logicals.?

2 ビュー (過去 30 日間)
noam Y
noam Y 2018 年 2 月 9 日
コメント済み: Stephen23 2018 年 2 月 9 日
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 :) .

採用された回答

Stephen23
Stephen23 2018 年 2 月 9 日
You have a variable named sum. Clear it:
clear sum
  2 件のコメント
noam Y
noam Y 2018 年 2 月 9 日
thanks! that fixed it. just for good measure, I changed the variable name entirely.
Stephen23
Stephen23 2018 年 2 月 9 日
Yes, I should have added "and never call any variable the same name as any inbuilt MATLAB function". Note that you should use which to check if a name is already used, e.g:
which sum -all

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by