我想要检测斑点的平均速度,一旦它被检测到它离开屏幕,我就无法设置如何设置要使用的值的边界。
以下是一些示例数据:
#35 x_cen=NaN y_cen=NaN curSpeed=0
Elapsed time is 0.263965 seconds.
#36 x_cen=NaN y_cen=NaN curSpeed=0
Elapsed time is 0.263827 seconds.
#37 x_cen=NaN y_cen=NaN curSpeed=0
Elapsed time is 0.420120 seconds.
#38 x_cen=3.052941e+01 y_cen=1.147059e+01 curSpeed=0
Elapsed time is 0.302205 seconds.
#39 x_cen=30 y_cen=1.104167e+01 curSpeed=6.813593e-01
Elapsed time is 0.294330 seconds.
#40 x_cen=30 y_cen=1.104167e+01 curSpeed=6.813593e-01
Elapsed time is 0.281333 seconds.
#41 x_cen=30 y_cen=1.104167e+01 curSpeed=6.813593e-01
Elapsed time is 0.293527 seconds.
#42 x_cen=NaN y_cen=NaN curSpeed=0
Elapsed time is 0.272795 seconds.
#43 x_cen=NaN y_cen=NaN curSpeed=0
Elapsed time is 0.271102 seconds.
#44 x_cen=NaN y_cen=NaN curSpeed=0
在此示例数据中,我希望对象的平均速度从第39帧开始到第41帧。
目前,我可以使用以下代码计算指定帧数的平均速度:
avgSpeed = (curSpeed + sum(speedData(end-2:end))) / 4;
我打算在if
语句中包含上述行,如果我能找到使用可变行号的方法。
答案 0 :(得分:0)
我使用以下代码来确定帧数和平均速度:
moving = false;
startFrame = 0;
endFrame = 0;
counter = 0;
speedTotal = 0;
if curSpeed > 0 && moving == false
counter = counter + 1;
speedTotal = speedTotal + curSpeed;
elseif curSpeed == 0
moving = false;
avgSpeed = speedTotal / counter
counter = 0;
avgSpeed = 0;
speedTotal = 0;
end