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
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!