LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create formula with lookup table

Solved!
Go to solution

Hi, I would like to convert formula in the below to labview format, any idea how this could be done easiest way?

I'm planning to use formula node but I'm not not sure about how to use lookup table inside the formula or is it even possible?

 

br, Jani

 

   
        Dim dblLookUp(,) As Double = New Double(3, 1) {{4, 4}, {10, 200}, {60, 3000}, {100, 7000}}
   
        If dblAbsValue >= 0 And dblAbsValue <= dblLookUp(0, 0) Then
            dblk = dblLookUp(0, 1) / dblLookUp(0, 0)
            dblValue = dblAbsValue * dblk
            'lblMode.Text = 1
        ElseIf dblAbsValue > dblLookUp(0, 0) And dblAbsValue <= dblLookUp(1, 0) Then
            dblk = (dblLookUp(1, 1) - dblLookUp(0, 1)) / (dblLookUp(1, 0) - dblLookUp(0, 0))
            dblValue = dblk * dblAbsValue - dblk * dblLookUp(0, 0) + dblLookUp(0, 1)
            'lblMode.Text = 2
        ElseIf dblAbsValue > dblLookUp(1, 0) And dblAbsValue <= dblLookUp(2, 0) Then
            dblk = (dblLookUp(2, 1) - dblLookUp(1, 1)) / (dblLookUp(2, 0) - dblLookUp(1, 0))
            dblValue = dblk * dblAbsValue - dblk * dblLookUp(1, 0) + dblLookUp(1, 1)
            'lblMode.Text = 3
        ElseIf dblAbsValue > dblLookUp(2, 0) And dblAbsValue <= dblLookUp(3, 0) Then
            dblk = (dblLookUp(3, 1) - dblLookUp(2, 1)) / (dblLookUp(3, 0) - dblLookUp(2, 0))
            dblValue = dblk * dblAbsValue - dblk * dblLookUp(2, 0) + dblLookUp(2, 1)
            'lblMode.Text = 4
        Else
            dblValue = dblLookUp(3, 1) '* Math.Sign(dblValue)
            'lblMode.Text = 5
        End If

        Return dblValue * intSign

0 Kudos
Message 1 of 5
(3,719 Views)
Solution
Accepted by topic author janijt

Hello janijt,

 

You can definitely use formula node for it. What you would do is to create a constant array for the lookup table. 

Here's an implementation in MathScript Node

 

Untitled.png

Andy Chang
National Instruments
Message 2 of 5
(3,698 Views)

Thanks for help!

 

br, Jani

0 Kudos
Message 3 of 5
(3,675 Views)

Hi Jani,

 

does it have to be a formula node? This looks like it could be translated easily into native G...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(3,668 Views)

Hi GerdW

 

No it does not, but I thinkthat formula node is easiest way to do it because calculation is not time critical.

 

br, Jani

0 Kudos
Message 5 of 5
(3,660 Views)