【发布时间】: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