我试图遍历大量的值并收集每秒的一个值的平均值。我无法使这段代码正常工作,据我所知,问题在于嵌套的while循环。我是否在制作范围错误,导致我无法迭代for循环索引?
数据是以ms为单位的时间戳和辐射计数。
a.data[i][0]
是时间戳,a.data[i][26]
是计数。
for (i = 0; i < a.data.length; i++){
// counts is the count of radiation over the last timeframe
var counts = 0;
// t1 is the start time
// t2 is the current iteration time
var t1, t2 = a.data[i][0];
while ((t2 - t1) < 1000){
t2 = a.data[i][0];
counts += a.data[i][26];
i++;
}
// Geiger Data is an array of { x:(time), y:(value)} datapoints.
GeigerData.push({x: (t1/1000), y: counts});
}
答案 0 :(得分:2)
你的问题源于这一行:
var t1, t2 = a.data[i][0];
定义JS变量并不像那样工作,并且在代码t1
中始终未定义。你真正想要的是
var t1 = a.data[i][0];
var t2 = t1;