Hi all.
I am having a problem with my loop.
I need anyone here explain to me whats going on with the code below.
Input euc_total[cluster][i]:
1.0000 0.0000 2.8284 4.2426
5.0000 4.2426 1.4142 0.0000
Code:
void Get_Min_Distance()
{
int clust = 0, doc = 0, doc_cluster = 0, doc_count = 0;
double min = 0.0;
for (int i = 0; i < ROW; i ++ )
{
min = euc_total[0][i];
for (int cluster = 0; cluster < cluster_num; cluster++)
{
if (euc_total[cluster][i] < min)
{
min = euc_total[cluster][i];
clust = cluster;
printf("\nmin= %.4f cluster=%d",min,cluster);//1
}
}
printf("\n%.4f -> Document [%d] in cluster [%d]", min, i, clust);//2
}
}
In the function above, I have 2 printf.
The first printf will display the "min" value and "cluster" value.
The problem is, it will display cluster 1 only, and I am wondering why it doesnt display starting with cluster 0.
Output:
min= 1.4142 cluster=1
min= 0.0000 cluster=1
The second printf has no such problem. It displays starting from cluster 0.
Output:
1.0000 -> Document [0] in cluster [0]
0.0000 -> Document [1] in cluster [0]
1.4142 -> Document [2] in cluster [1]
0.0000 -> Document [3] in cluster [1]
I am thinking why the first printf cant display cluster starting with 0 while the second printf can do that??
Anyone..pls explain.
And how to solve this problem.
Thanks in advance.