【问题标题】:Classification issue [closed]分类问题[关闭]
【发布时间】:2016-08-19 15:33:48
【问题描述】:

我有一个包含 4 个变量的结构数组。

records[i].time
records[i].xaxis
records[i].yaxis
records[i].zaxis

i 将记录索引。其最大值为n。在上面,records[i].time 在数组中按时间升序排列,单位为毫秒。我必须找到

maximum of records[i].xaxis
minimum of records[i].xaxis
maximum of records[i].yaxis
minimum of records[i].yaxis
maximum of records[i].zaxis
minimum of records[i].zaxis

对于records[i].time中每一秒的一组,求差值(最大-最小)并赋值给另一个结构体

neighbour[k].difx
neighbour[k].dify
neighbour[k].difz

其中 k 将是每个组的索引。 这是我到目前为止所做的事情

i = 0; //initialize counter
int k = 1; // second
int j; //internal counter
float minx, maxx, miny, maxy, minz, maxz; // min and max values of the other 3 fields of the struct records
for ( i = 0; i < n; i++){
//initialize min and max 
    maxx = records[i].xaxis;
    minx = records[i].xaxis;
    maxy = records[i].yaxis;
    miny = records[i].yaxis;
    maxz = records[i].zaxis;
    minz = records[i].zaxis;
    //start looking for the maximum and the minimum
    for( j = i; j < n; j++){
        if(records[j].time < k * 1000){//check only for values within the desired time period
            if( records[j].xaxis > maxx ){
                maxx = records[j].xaxis;
            }
            if( records[j].xaxis < minx ){
                minx = records[j].xaxis;
            }
            if( records[j].yaxis > maxy ){
                maxy = records[j].yaxis;
            }
            if( records[j].yaxis < miny ){
                miny = records[j].yaxis;
            }
            if( records[j].zaxis > maxz ){
                maxz = records[j].zaxis;
            }
            if( records[j].zaxis < minz ){
                minz = records[j].zaxis;
            }
        }
    }//once the proper values are found save the difference between max and min.
    neighbour[i].difx = maxx-minx;
    neighbour[i].dify = maxy-miny;
    neighbour[i].difz = maxz-minz;  
    k++;    
}

我得到的结果不同。感谢您的帮助。

【问题讨论】:

  • 问题是什么?您是否遇到任何错误?
  • 我对这个问题的理解是你试图为每 1 秒的数据定义某种边界框。如果您告诉我们记录是否按时间排序会有所帮助。
  • 投票以“不清楚你在问什么”来结束这个

标签: c max classification min


【解决方案1】:

从你所说的。我假设 records[i].time 是按升序排列的。那么代码就变成了。

i = 0; //initialize counter
int k = 1; // second
float minx, maxx, miny, maxy, minz, maxz; // min and max values of the other 3 fields of the struct records

//initialize min and max 
maxx = records[0].xaxis;
minx = records[0].xaxis;
maxy = records[0].yaxis;
miny = records[0].yaxis;
maxz = records[0].zaxis;
minz = records[0].zaxis; 

for ( i = 1; i < n; i++){
//start looking for the maximum and the minimum
    if(records[i].time <= k * 1000){//check only for values within the desired time period
        if( records[i].xaxis > maxx ){
            maxx = records[i].xaxis;
        }
        if( records[i].xaxis < minx ){
            minx = records[i].xaxis;
        }
        if( records[i].yaxis > maxy ){
            maxy = records[i].yaxis;
        }
        if( records[i].yaxis < miny ){
            miny = records[i].yaxis;
        }
        if( records[i].zaxis > maxz ){
            maxz = records[i].zaxis;
        }
        if( records[i].zaxis < minz ){
            minz = records[i].zaxis;
        }
    }
    else
    {
        neighbour[k-1].difx = maxx-minx;
        neighbour[k-1].dify = maxy-miny;
        neighbour[k-1].difz = maxz-minz;  
        k++;    
        maxx = records[i].xaxis;
        minx = records[i].xaxis;
        maxy = records[i].yaxis;
        miny = records[i].yaxis;
        maxz = records[i].zaxis;
        minz = records[i].zaxis; 
    }

}

【讨论】:

  • 这段代码对 x 和 y 工作得很好,但它对 z 给出了难以理解的答案。我检查了我的数据,他们没问题。有什么想法吗?
  • 我找到了。一个小错字,在我提供的代码和你给我的代码中都有。
猜你喜欢
  • 2019-11-30
  • 2012-11-02
  • 1970-01-01
  • 2020-08-02
  • 2012-04-03
  • 2022-01-21
  • 1970-01-01
  • 2017-11-19
  • 2018-06-11
相关资源
最近更新 更多