我有以下转换表:
我需要将第二列的值转换为第一列中的值,作为连续变量。
当前,我正在尝试编写一个从第二列接受值的函数,检查其有效性,然后使用以下转换公式进行数据转换:
当前代码如下:
Public Function ReScale (input As Double)
'Max and Min values of the old scale.
Dim MinOld As Double: MinOld = 2
Dim MaxOld As Double: MaxOld = 6
'Test input value validity.
If input > MaxOld Or input < MinOld Then
ReScale = CVErr(xlErrNA)
End
Dim MinNew As Double
Dim MaxNew As Double
'Find in which interval the input value belongs.
If input >= 5.5 Then
MinOld = 5.5
MaxOld = 6.0
MinNew = 85
MaxNew = 100
ElseIf input >= 4.50 And input <= 5.49 Then
MinOld = 4.50
MaxOld = 5.49
MinNew = 65
MaxNew = 84
...` <--------------------- Question?
'Transform the old data to the new scale.
ReScale = ( (MaxNew - MinNew) / (MaxOld - MinOld) ) * (input - MaxOld) + MaxNew
End Function
我的问题是:
我应该根据变量值搜索MaxNew
,MinNew
,MaxOld
和MinOld
,还是应该使用绝对最小值和最大值?
有没有更简单的方法?