A=[10 11; 20 21; 30 31; 40 41; 50 51; 60 61; 70 71]
PB = [1 1 3 3 2 2 2]
C = A (PB==3,:)
D = mean(C)
SD = size(C,1)
Results:
A =
10 11
20 21
30 31
40 41
50 51
60 61
70 71
PB =
1 1 3 3 2 2 2
C =
30 31
40 41
D =
35 36
SD = 2
Simplified code:
for i=1:K
centroids(i,:) = mean( X(idx==i,:) );
endfor
No comments:
Post a Comment