LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an array to a formular node

Solved!
Go to solution

I have an array e.g [0, 2, 4, 6, 8]. I want to pass this array to a formula node which calculate the square of each of the element of the input array, and show the resultant array.

For example, the formula is "square". So output array should be [0, 4, 16, 36, 64]

I did like this but there was an error..

Can someone please help?

0 Kudos
Message 1 of 12
(5,954 Views)

array_element_operation.png

0 Kudos
Message 2 of 12
(5,952 Views)

Why not just use the X^2 function on the numeric palette?

 

The problem with your formula node is that you don't have the Y output defined as an array.  Also, I don't think you can do math on arrays like that in a formula node.  You'd have to put in a For Loop and go through it element by element.

 

Message 3 of 12
(5,947 Views)

If there is only 1 variable in the equation, I'm a fan of the expression node.  But in this case, I'm with Ravens Fan: use the built in primitive.

 

expression node.png



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 12
(5,941 Views)
Solution
Accepted by splee

Here is how you do it with a formula node.

 

You tell me which looks easier to code?

 

It took me 2 seconds using the square function.  And 10 minutes to get the syntax right for the formula node.

 

Message 5 of 12
(5,936 Views)

The squaring function is easier, but the formula node looks more impressive.Smiley Happy

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 6 of 12
(5,913 Views)

I didn't know you could use arrays in the function node.  That'll give me something new to play with.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 12
(5,905 Views)

@MoReese wrote:

The squaring function is easier, but the formula node looks more impressive.Smiley Happy


Head over to the Rube Goldberg Thread. You'll be amazed! Smiley Very Happy

0 Kudos
Message 8 of 12
(5,892 Views)

RavensFan,

 

Could you explain how you got that? I have a similar situation but the formula it not that simple.

 

Thanks! 

0 Kudos
Message 9 of 12
(5,732 Views)

I don't know what you are looking for.  Are you looking for the equivalent LabVIEW code for what is in the formula node?  Or are you looking to turn the variable y into a 2-D array so that your formula is in a loop to convert all the 2-D array X-values to Y-values?

0 Kudos
Message 10 of 12
(5,723 Views)