필터 지우기
필터 지우기

how to make sum of same elements in binary matrix

조회 수: 2 (최근 30일)
Lukas
Lukas 2014년 3월 22일
댓글: Lukas 2014년 3월 26일
hello. how to make sum of same elements in binary matrix by using "for"? code that a made makes only sum of true elements. i want to make sum of all elements...
if true
function SumE = compare( BW1 , BW2 )
for a=1:110
for b=1:110
if (BW1(a,b)==BW2(a,b))
SumE=SumE+1;
end
end
end
end
end
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 22일
This is not clear, can you illustrate with a short example?
Jan
Jan 2014년 3월 22일
You code fails due to the missing definition of SumE before the loops.

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

채택된 답변

Jan
Jan 2014년 3월 22일
Your function counts the number of elements, which have equal value in both matrices. There is no test, if the elements are TRUE or FALSE. Therefore I do not understand the relation between the question and the code.
A simplified version of your program:
function SumE = compare(BW1, BW2)
SumE = sum(BW1(:) == BW2(:));
  댓글 수: 1
Lukas
Lukas 2014년 3월 26일
sorry if i described it worst. i thought something like this:
function NumPixels = compare( BW1 , BW2 )
C=sum(sum(BW1(:)&BW2(:)));
D=sum(sum(~BW1(:)&~BW2(:)));
NumPixels=C+D;
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by