【发布时间】:2014-07-11 22:00:17
【问题描述】:
所以我正在编写一个低通加速度计函数来缓和加速度计的抖动。我有一个 CGFloat 数组来表示数据,我想用这个函数来抑制它:
// Damps the gittery motion with a lowpass filter.
func lowPass(vector:[CGFloat]) -> [CGFloat]
{
let blend:CGFloat = 0.2
// Smoothens out the data input.
vector[0] = vector[0] * blend + lastVector[0] * (1 - blend)
vector[1] = vector[1] * blend + lastVector[1] * (1 - blend)
vector[2] = vector[2] * blend + lastVector[2] * (1 - blend)
// Sets the last vector to be the current one.
lastVector = vector
// Returns the lowpass vector.
return vector
}
在这种情况下,lastVector 在我的程序顶部定义如下:
var lastVector:[CGFloat] = [0.0, 0.0, 0.0]
vector[a] = ... 形式的三行给了我错误。关于我为什么会收到此错误的任何想法?
【问题讨论】:
-
作为我的旁注,我传递给它一个 [CGFloat] 数组
-
您遇到了什么错误?发生了哪些错误?
-
错误出现在标题中,并且所有这三行都完全相同。上面提到的 lastVector 也是一个 CGFloat 数组,被定义为一个全局变量。它不是错误的根源,因为没有它,同样的错误仍然存在。