LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I input both an array and a double precision constant into the formula VI?

Solved!
Go to solution

I'd like to compute a new 1-D array using the Formula VI. Is LabVIEW "smart enough" to input a 1-D array and a double precision constant into the Formula VI and output a 1-D array given basic commands?

 

For example, can I input the array [1 2 3] and the constant [2] and say "array*constant-1" in the Formula VI and get an output of [1 3 5] or do I need to do a for loop or something?

0 Kudos
Message 1 of 10
(4,702 Views)

Which "Formula" VI are you referring to? The only "Formula" VI I'm aware of is an Express VI that has no inputs. There are other "formula" VIs, such as "Eval Formula Node", "Eval Formula String", "Eval Parsed Formula Node", ....

0 Kudos
Message 2 of 10
(4,696 Views)
Solution
Accepted by topic author twolfe13

Actually the Formula Express VI looks like it can have up to 8 inputs.

 

Twolfe, the easiest way to find an answer to this type of question is to try it.  Smiley Wink

 

I didn't know this (because I have no reason to use that express VI), but you can wire an array to it.  It treats it just like any other LabVIEW operations on arrays.

But if you needed to do some looping, then you should already be avoiding Express VI's and start doing real programming.

 

 

 

Message 3 of 10
(4,677 Views)

Thanks for the help. I'm just learning LabVIEW, and the Formula Express VI is a life saver. The equations I'm working with are non-linear and include some rather large expressions, so it really helps save me time coding.

0 Kudos
Message 4 of 10
(4,654 Views)

If you are doing more complicated equations where you need the text-based calculations, you might want to consider looking into the formula node.  There is less overhead with it, it doesn't hide the formulas, and it has more programming capability such as looping available.

Message 5 of 10
(4,647 Views)

Thanks, this looks great actually. I'm a fan of shoving in some C in the middle of my code.

0 Kudos
Message 6 of 10
(4,645 Views)

 


@Ravens Fan wrote:

Actually the Formula Express VI looks like it can have up to 8 inputs.


Hah, just goes to show you how much I use Express VIs. Smiley Very Happy

 

0 Kudos
Message 7 of 10
(4,631 Views)

Seeing as how moderators would like me to keep to this specific post, I have MANY more questions regarding the formula node.

 

I'm trying to figure out how to use arrays in the formula node. It seems that I have to write for loops to do arithmetic computations on the arrays or else the formula node just tries to pop out a constant.

 

Right now I have the following code:

 

int i;

for(i=0; i<sizeOfDim(tdo); i++)

{

    pp[i] = pe-pb*(td0[i]-tw0[i])/1500;

}

 

I used sizeOfDim because I saw that it was in the list of functions that can be included in the formula node. I'm trying to go no higher than whatever the dimension is of the td0 array. In the Formula Express VI, I would just dump all of this in and write "pe-pb*(td0-tw0)/1500" and it would pop out the pe array which is what I want. I'm trying to get more accustomed to using the formula node, but I keep running into snags when using both array and constants. I'd like to get a basic format down so that I can continue to do terrible terrible things to these arrays, haha.

 

I'd also like to be able to multiply the elements of the arrays by themselves (square them). In the Formula Express Vi I write something like td0**2. This would be very similar in the formula node if td0 was a constant. Unfortunately, it's an array. It's been about 5 years since I last used C, and it was minimal and a special version of it. It seems that LabVIEW is ALSO using a special version of C. It seems that I have to use included commands only. That is to say, I can't do something like #include <whatever.h> and expect new things to be available.

 

P.S. I really think that moving to a new topic would be better here since this has very little to do with the Formula Express VI.

0 Kudos
Message 8 of 10
(4,622 Views)

One error is that sizeOfDim(td0) should be sizeOfDim(td0,0) although I don't really understand what the 0 means. I still can't get an array output, however.

0 Kudos
Message 9 of 10
(4,606 Views)

The second parameter for sizeOfDim is which dimension to return the size. For instance, a matrix is an M x N object ( a 2 dimensional array). So sizeOfDim(matrix,0) returns M, and sizeOfDim(matrix,1) returns N.

 

Here's a snippet inputing an array and writing each value to the output. In this example the output is constantly squashed by the next element, but you could put different logic in the loop.

 

FormulaNodeExample.png

- Regards,

Beutlich
0 Kudos
Message 10 of 10
(4,589 Views)