📄 step2.m
字号:
% step2.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% All important data in (cell) array s.
% The first row are s(1,:)centers,then s(2,:)samples,s(3,:)in-class distance!!
% sample classification based on minimum distance princple.
% So it include Step 4,5,6,8
s=cell(5,c);
for i=1:c
s{1,i}=Z(i,:);
end
%分类
for i=1:c % 清空s{2.i}
s{2,i}=[];
end % 分类
for i=1:length(sample)
[temp minposition]=mindistance(Z,sample(i,:));
clear temp
s{2,minposition}(end+1,:)=sample(i,:);
end
for i=1:c %修改聚心
if size(s{2,i},1)~=0
s{1,i}=[mean(s{2,i}(:,1)) mean(s{2,i}(:,2))];
Z(i,:)=s{1,i};
end
end
% 统计每类样本数
for i=1:c
s{5,i}=size(s{2,i},1);
end
%计算类内距离
for i=1:c
if size(s{2,i},1)~=0
s{3,i}= inclassdistance(s{1,i},s{2,i});
end
end
% 计算总平均距离
d_avg=0;
for i=1:c
d_avg=d_avg+sum(s{5,i}*s{3,i})/size(sample,1);
end
% Step 8
for k=1:c
s{4,k}=std(s{2,k},1,1);
% the second 1 controls std use the form of standard deviation, the
% third 1 means the 1st demension
% see more details in the fucntion 'std'
end
% names
s{1,end+1}='center';
s{2,end}='sample';
s{3,end}='in-class distance';
s{4,end}='standard deviation';
s{5,end}='number of samples';
%%%Author: Feng Shuo%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -