LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace MathScript with Formula Node

Solved!
Go to solution

For some reason, Math Script module is only licensed for my 32-bit LabVIEW 2014, but not for my 64-bit version installed on the same machine.

 

Therefore, I have to replace a MathScript routine with Formula Node. Here is the code:

 

j=1

for i = 1 : 2 : n-1

   Odd(j) = A(i)

   j=j+1

end

j-1

for i = 2 : 2 : n

   Even(j) = A(i)

   j=j+1

end

 

The code simply takes in an Array 'A' of size 'n', and outputs two arrays, one for the odd indexes and another for the even ones. I tried doing it in Forumla Node but I keep getting errors when defining Odd[n], LabVIEW only accepts Odd[10] or any specific number, which is not very helpful.

 

0 Kudos
Message 1 of 4
(3,290 Views)
Solution
Accepted by topic author student_1
Message 2 of 4
(3,277 Views)

Why not run the A array into a For Loop (where the input tunnel will default to an indexing tunnel), add a boolean Shift register that you can label "Is Even", initialized to False, create two more Shift Registers that will become Even and Odd outputs, and put a Case Statement inside the For Loop, with Is Even wired to its selector (and wired through the Case Statement with a Not function to invert it before connecting it to the far end).  I shouldn't have to tell you that the True ("Is Even") case you add the A element to the Even array, while the False case you add the A element to the Odd array.

 

If you are using a more recent version of LabVIEW (I think 2012 has this feature) that allows you to have Conditional Indexing output tunnels, you don't need the Case Statement nor the Even and Odd shift registers -- just create two conditional output tunnels, wire "Is Even" to the conditional terminal of one and the negation of "Is Even" to the the conditional terminal of the other, and wire the A element to both.  When the loop exits, all of the A elements with even indices will be in "Is Even" and odd will be in "Is Odd".

 

Note that I might have made a silly mistake and be "off by one" because LabVIEW indexes arrays starting with 0, not 1.  Do a simple experiment and if "backwards", simply invert Even and Odd.

 

I'm deliberately not putting a picture here.  If you don't understand what I'm talking about, read the Help on For loops, indexing, shift registers, etc. and spend some time with the free on-line LabVIEW tutorials.

 

Bob Schor

Message 3 of 4
(3,246 Views)

You can now try out the LabVIEW MathScript 2016 beta with 64-bit support for Windows, Mac and Linux:

http://digital.ni.com/betaprogram/mainbetacust.nsf/main.htm

 

0 Kudos
Message 4 of 4
(2,992 Views)