clusterstats.m

来自「使用matlab进行实现的kmeans算法。数据集。」· M 代码 · 共 36 行

M
36
字号
function [nr,m,v] = clusterstats(x,c,K)% CLUSTERSTATS(x,c) computes the statistics for each cluster% [nr,m,v] = clusterstats(x,c[,K])%	x  - d*n matrix of samples%	c  - 1*n matrix with the cluster identity for each sample x(:,i)%	K  - the number of different clusters (max(c) if omitted)% returns%	nr - 1*K matrix with the number of samples in each cluster%	m  - d*K matrix with the mean for each cluster%	v  - d*K matrix with the variance for each component% Copyright (c) 1995-2001 Frank Dellaert% All rights Reservedif (nargin<3) K=max(c);end% get dimensions of data[d,n] = size(x);% allocate spacenr = zeros(1,K);sum = zeros(d,K);sumsq = zeros(d,K);% calculate statsfor i=1:K   ci=find(c==i);   nr(i)=length(ci);   xi=x(:,ci);   m(:,i)=mean(xi,2);   v(:,i)=std(xi,1,2).^2;end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?