分类问题
Classification issue
我有一个包含 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++;
}
我得到的结果不同。谢谢你的帮助。
根据你所说的。我假设 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;
}
}
我有一个包含 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++;
}
我得到的结果不同。谢谢你的帮助。
根据你所说的。我假设 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;
}
}