LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to change content in the formula node of the current vi

Actually I want to give formula with array index. 

My formula p=a[0]-30; But i couldnot give array index in the formula expression..

Please help me in this issue.

0 Kudos
Message 1 of 15
(6,844 Views)

Hi Muthu92,

 

Please refer following solutions.

Screen Shot 2014-06-12 at 13.17.23.png

HTML tutorial  HTML tutorial
162+ CLDs & 10 CLAs Trained
LabVIEW Training resources
Message 2 of 15
(6,815 Views)

Thank you for you reply . Can I give change content of the formula node? I want programmatically edit content of the formula node.

 

0 Kudos
Message 3 of 15
(6,802 Views)

To use scripting to change the content of the formula node requires two things:

1. The formula node you are targetting must not be in a running VI in order to be able to edit it

2. You need the full LabVIEW dev environment present.

 

Item 1 prevents you from using scripting in the same VI to change the formula node expression, so you need to run your script from a different VI.

Item 2 means you cannot subsequently create an executable from the solution, because the run-time environment alone cannot recompile the formula node.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 4 of 15
(6,796 Views)

Ya. Thank you sir. 

I have Labview Full Development system . But using Eval Formula node.vi . I can't give formula of array variable and array input. My formula is P=a[0]/15-a[5]. where P is output variable and a[] is input vable. So I need to give array input as well as array variable. 

0 Kudos
Message 5 of 15
(6,788 Views)

Just out of interest, why are you using a Formula Node for this simple calculation? You could create a simple subVI that performs this calculation with the array a as one input, the index i as another input, and an output value P calculated using simple index array, divide and subtract functions.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 6 of 15
(6,773 Views)

@Muthu92 wrote:

Ya. Thank you sir. 

I have Labview Full Development system . But using Eval Formula node.vi . I can't give formula of array variable and array input. My formula is P=a[0]/15-a[5]. where P is output variable and a[] is input vable. So I need to give array input as well as array variable. 


I have to agree with the post above mine, for a simple calculation it is likely faster, easier, and simpler to read for others viewing your code if you just do all calculations in LabVIEW.

 

If your actual calculation is significantly more intense and/or you insist on using a formula node, then I have a half-solution.  From what I understand, Eval Formula Node VI does not allow you to pass entire array inputs.  You have to pass variable names and values in a one-to-one manner. 

 

To get around this, rename the variables in the function (i.e. a[0] == a, a[5] == b) and index your input array using LabVIEW code before even using the formula node.  It is a ltitle messier, but this will allow you to extract the elements from arrays as you need them, and then you can just reference them in the formula node by a different name:

 

formula.png

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 7 of 15
(6,767 Views)

Thank you for your reply. It is very useful for me.  But i can't give conditional operator in that operator. It is showing error.

My Test cases

A[0]+A[1]>150

A[31]-50 <100.

0 Kudos
Message 8 of 15
(6,733 Views)

@Muthu92 wrote:

Thank you for your reply. It is very useful for me.  But i can't give conditional operator in that operator. It is showing error.

My Test cases

A[0]+A[1]>150

A[31]-50 <100.


If those are your exact statements, then they don't make sense in a formula node.  You have to use them in an if-statement or some other type of control logic.  This mimics text-based programming languages such as C... See here for instructions on formula node syntax: http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/formula_node_syntax/

 

For instance, you COULD say something like:

 

**In this example, let A[0] == x, A[1] == y, A[31] == z**

 

if(x+y>150)

/* do something if this is true */

else if(z-50 < 100)

/* do something else */

 

EDIT: 

It should also be noted that Variable Names MUST be lowercase!! I just discovered this 😛

 

 

EDIT2:

 

I stand corrected.  After trying to create an example and digging through the LabVIEW Help, I stumbled across this:

 

Differences between the Parser in the Mathematics VIs and the Formula Node
The parser in the Mathematics VIs supports all elements that Formula Nodes support with the following exceptions:

Variables—Only a, a0, ..., a9, ... z, z0, ..., z9, are valid.
Logical, conditional, inequality, equality—?:,, &&, !=, ==, <, >, <=, and >= are not valid.
Functions—atan2, max, min, mod, pow, rem, and sizeOfDim are not valid. You can use these functions in a Formula Node or use their corresponding LabVIEW functions.

 

So it DOES NOT seem like Eval Formula Node can do conditionals like you want.  I would just implement them using a LabVIEW based algorithm after all.  Trying to out smart the formula nodes to avoid simple LabVIEW code is just too much of a hassle 😛

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 9 of 15
(6,724 Views)

Can you tell us more about your application? Why do you need to change the formula? What is the range of possible functions/formulas you need to use? 

 

If you give us more information about what your real need is, someone may be able to offer a better solution.

 

Lynn

Message 10 of 15
(6,693 Views)