findding neares label
2 views (last 30 days)
Show older comments
Hi I have the following 3 matrix. I =
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I1 =
0 0 0 0 0 0
0 1 1 1 1 0
1 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
I2 =
0 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 1
0 1 0 0 1 0
0 0 1 1 0 0
0 0 0 0 0 0
I need to know the 1s in I1 is closer to the which matrices' 1s. Here If some one looks at the matrix then obviously 1s in I1 is closer to the 1s in I than in I2.
Is there any one to help?
Thanks
0 Comments
Accepted Answer
Andrei Bobrov
on 20 Jun 2011
so
D = bwdist(I)
P1 = sum(D(logical(I1)))
P2 = sum(D(logical(I2)))
if P1 < P2 , disp('I1 is closer to the 1s in I than in I2');
else disp('I2 is closer to the 1s in I than in I1'); end
0 Comments
More Answers (1)
Walter Roberson
on 20 Jun 2011
V = 1:size(I,1);
Ipos = V * I;
I1pos = V * I1;
I2pos = V * I2;
I1score = sum(abs(Ipos-I1pos));
I2score = sum(abs(Ipos-I2pos));
if I1score < I2score
%I1
elseif I1score > I2score
%I2
else
%equal
end
This is based on my arbitrary meaning of "closer", as you are very vague as to what "closer" means.
See Also
Categories
Find more on Creating and Concatenating Matrices 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!