【发布时间】:2013-06-17 12:33:05
【问题描述】:
我在 MATLAB 上使用 k-means。为了处理有效的簇,它需要循环直到簇的位置不再改变。循环将显示迭代过程。
我想计算在该集群过程中发生了多少循环/迭代。下面是循环/迭代处理部分的sn-p:
while 1,
d=DistMatrix3(data,c); %// calculate the distance
[z,g]=min(d,[],2); %// set the matrix g group
if g==temp, %// if the iteration does not change anymore
break; %// stop the iteration
else
temp=g; %// copy the matrix to the temporary variable
end
for i=1:k
f=find(g==i);
if f %// calculate the new centroid
c(i,:)=mean(data(find(g==i),:),1);
end
end
end
我所要做的就是定义迭代变量,然后编写计算部分。但是,我必须在哪里定义变量?怎么做?
我们将不胜感激所有答案。
谢谢。
【问题讨论】:
-
你的“循环/迭代”是什么意思?您有两个不同的循环(
while中的for)。是否还要计算for循环迭代的次数?
标签: matlab variables iteration counting