All All: %jumlah Data Pada Cluster
All All: %jumlah Data Pada Cluster
clear all;
close all;
randnumb = 100;
M = zeros(randnumb,2);
label = zeros(randnumb,1);
for a=1:randnumb
M(a,1) = unidrnd(randnumb);
M(a,2) = unidrnd(randnumb);
end
c1 = [unidrnd(randnumb) unidrnd(randnumb)];
c2 = [unidrnd(randnumb) unidrnd(randnumb)];
c1_temp = -ones(1,2);
c2_temp = -ones(1,2);
iterasi = 0;
while((c1(1,1)~=c1_temp(1,1)) && (c1(1,2)~=c1_temp(1,2)) && (c2(1,1)~=c2_temp(1,1))
&& (c2(1,2)~=c2_temp(1,2)))
iterasi = iterasi+1;
jum_c1 = 0;
jum_c2 = 0;
for a=1:randnumb
x = M(a,1);
y = M(a,2);
c1x = c1(1,1);
c1y = c1(1,2);
c2x = c2(1,1);
c2y = c2(1,2);
rx_c1 = jx_c1/jum_c1;
ry_c1 = jy_c1/jum_c1;
rx_c2 = jx_c2/jum_c2;
ry_c2 = jy_c2/jum_c2;
c1_temp(1,1) = c1(1,1);
c1_temp(1,2) = c1(1,2);
c2_temp(1,1) = c2(1,1);
c2_temp(1,2) = c2(1,2);
c1(1,1) = round(rx_c1);
c1(1,2) = round(ry_c1);
c2(1,1) = round(rx_c2);
c2(1,2) = round(ry_c2);
disp('Iterasi ke');
disp(iterasi);
end
disp('Jumlah data biru');
disp(jum_c1);
disp('Jumlah data merah');
disp(jum_c2);
plot(c1(:,1),c1(:,2),'xb','MarkerSize',15,'LineWidth',3); hold on
plot(c2(:,1),c2(:,2),'xr','Markersize',15,'LineWidth',3); hold on
grid on