findding neares label
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 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 Kommentare
Weitere Antworten (1)
Walter Roberson
am 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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!