资源简介
chameleon算法matlab代码,很经典的一个算法,可用于聚类研究.
代码片段和文件信息
clear;
clc;
%产生随机点
img=zeros(100200);
data=rand(1100);
x=zeros(1100);
y=zeros(1100);
for i=1:100
loc=ceil(data(1i)*20000);
x(1i)=ceil(loc/200);
y(1i)=mod(loc200);
if (y(1i)==0)
y(1i)=200;
end
img(x(1i)y(1i))=255;
end
%image(img);
%构造距离矩阵
processed=1000000;
for i=1:100
for j=i+1:100
dist(ij)=(x(1i)-x(1j))*(x(1i)-x(1j))+(y(1i)-y(1j))*(y(1i)-y(1j));
dist(ji)=processed;
end
dist(ii)=processed;
end
for i=1:100
category(1i)=i;
end
num_category=100;
%反复挑选距离最近的两类合并
while (num_category>7)
mindist=1000000;
for i=1:100
for j=i+1:100
if (dist(ij) mindist=dist(ij);
minp1=i;
minp2=j;
end
end
end
dist(minp1minp2)=processed;
dist(minp2minp1)=processed;
for i=1:100
if (category(1i) == minp2)
category(1i)=minp1;
end
end
for i=1:100
if (dist(minp2i) dist(minp1i)=dist(minp2i);
end
dist(minp2i)=processed;
dist(iminp2)=processed;
end
num_category=num_category-1;
end
%整理类别标记
for i=1:100;
labeled(1i)=0;
end
categories=0;
for i=1:100
kind=category(1i);
if (labeled(1kind)==0)
categories=categories+1;
for j=i:100
if(category(1j)==kind)
category(1j)=categories;
end
end
labeled(1categories)=1;
end
end
%显示
x1=zeros(1100);
y1=zeros(1100);
x2=zeros(1100);
y2=zeros(1100);
x3=zeros(1100);
y3=zeros(1100);
x4=zeros(1100);
y4=zeros(1100);
x5=zeros(1100);
y5=zeros(1100);
x6=zeros(1100);
y6=zeros(1100);
x7=zeros(1100);
y7=zeros(1100);
for i=1:100
if(category(1i)==1)
x1(1i)=x(1i);
y1(1i)=y(1i);
elseif (category(1i)==2)
x2(1i)=x(1i);
y2(1i)=y(1i);
elseif (category(1i)==3)
x3(1i)=x(1i);
y3(1i)=y(1i);
elseif (category(1i)==4)
x4(1i)=x(1i);
y4(1i)=y(1i);
elseif (category(1i)==5)
x5(1i)=x(1i);
y5(1i)=y(1i);
elseif (category(1i)==6)
x6(1i)=x(1i);
y6(1i)=y(1i);
elseif (category(1i)==7)
x7(1i)=x(1i);
y7(1i)=y(1i);
end
end
plot(x1y1‘b.‘x2y2‘g.‘x3y3‘r.‘x4y4‘c.‘x5y5‘m.‘x6y6‘y.‘x7y7‘k.‘);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2556 2005-01-05 11:42 cha.m
文件 1227 2005-08-23 10:10 说明.txt
- 上一篇:字符识别matlab实现
- 下一篇:用matlab实现基于灰度的阈值分割算法
评论
共有 条评论