寻找数组中的中心

寻找数组中的中心

//寻找中心
for (int k = 0; k < line_ks_group.size();k++) {
    QList<double> list_ks2 = line_ks_group.at(k);
    QMap<double, int> index_ks_map;

    index_ks_map.insert(list_ks2.at(0), 1);

    for (int m = 1; m < list_ks2.size();m++) {
        double index_ks_value = list_ks2.at(m);
        QList<double> list_ks3 = index_ks_map.keys();
        
        int isExist2 = -1;
        for (int n = 0; n < list_ks3.size();n++) {
            double index_key6 = list_ks3.at(n);
            int key6_value = index_ks_map.value(index_key6);
            if (abs(index_ks_value - index_key6)<5.0) {
                //已存在,更新
                //index_ks_map.insert(index_key6, key6_value+1);
                isExist2 = n;
            }
            
        }

        if (isExist2 !=-1) {
            double index_key6 = list_ks3.at(isExist2);
            int key6_value = index_ks_map.value(index_key6);
            index_ks_map.insert(index_key6, key6_value + 1);
        }
        else 
        {
            index_ks_map.insert(index_ks_value, 1);
        }
    }

    line_ks_center.append(index_ks_map);
}

 

原始数据:

(-21.5047, -21.3685, -21.5047, -21.5486, -21.3685, -21.5047, -21.4859, -21.3685), 
(-21.8523, -21.379), 
(26.6946, -252.101)

 

输出:

line_ks_center: 
(QMap((-21.5047, 8)), 
QMap((-21.8523, 2)), 
QMap((-252.101, 1)(26.6946, 1))

 

 

####################

posted @ 2022-03-27 16:02  西北逍遥  阅读(37)  评论(0编辑  收藏  举报