findding neares label

2 次查看(过去 30 天)
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

采纳的回答

Andrei Bobrov
Andrei Bobrov 2011-6-20
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

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-6-20
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.
  1 个评论
Mohammad Golam Kibria
for I1 and I,pixel distance having 1 are 0,0,1,1,0,0 and for I1 and I2 are 0,2,root(3),root(3),2,0, so it may be consider that s in I1 is closer to the 1s in I than in I2.
perhaps now it is clear

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by