我有一个描述分段函数的表格,其中包含详细的梯度、截距和界限。我试图获得任意等级的精确值(如果有小数点的话)。这里的问题是边界没有相同的大小,所以我无法描述布尔范围,如:0< {upper bound} - {value} <= {size}. If I want to describe it like that, I will have to go for: {lower bound} < {value} <= {upper bound}, which in and of itself is okay, except that the formula is monstrously long and painful to look at if I were to use IFS with this very table because of how many conditions I have (),我觉得这是非常低效的。我该如何解决这个问题?
这是 VLOOKUP 或 INDEX(MATCH) 的一个很好的例子;由于分数是有序的,它会自动返回下限或上限行,然后您可以从同一行选择正确的梯度和截距。
假设您要检查的分数(例如 89.5)位于单元格 A1 中,表格中的数据位于 B1:E10 中,则:
A2 中的=MATCH(A1,B1:B10,1)
将为您提供 B1:B10 中小于 89.5 的最大值的行号(在本例中,i 返回对应于下限 89 的“2”)。
现在在A3中你可以使用
=INDEX(C1:C10,A2)
来获取相应的梯度,同样使用=INDEX(D1:D10)
来获取截距。
您也可以将它们组合起来:
=INDEX(gradient_range,MATCH(score,lower-bound-range,1))