LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Really need Min(a,b) and Max(a,b) function in "Eval formula node"

Hi all,
 
I've been using the 'Eval formula node" to let the user of my app configure his own calculations,
but now I've found out that the "Eval formula node" doesn't support these functions.
 
e.g        y= min (a,b)
or         y = max (a+3, c-4)
 
I considered adding them myself to the Eval formula node's subvi's,
but franckly I've never seen such complex subvi's 🙂
 
Is pretty urgent. Any ideas?
0 Kudos
Message 1 of 6
(4,174 Views)
Only thing I can think of would be to essentially create a macro by using a search and replace string within the formula.  You'd have to use a regular expression (match pattern) to find the min and max functions, then you'd have to parse the pattern match into tokens and then do the apropriate calculations and replace the original.
 
Best of Luck,
Ryan K.
0 Kudos
Message 2 of 6
(4,147 Views)

As a followup to what Ryan wrote. If you manage to do a search & replace "preprocessing" of the formula string, you can use the following expressions to make x=min(a,b) and y=max(a,b) because the sign-function is allowed in the Eval formula node.

 

x = b*(sign(a-b)+1)/2 + a*(sign(b-a)+1)/2;
y = a*(sign(a-b)+1)/2 + b*(sign(b-a)+1)/2;

 

There are probably other ways to do it, requiring fewer operations or simpler to read, but this is what I could think of when I faced the same problem. It can be altered to emulate many relational operators and the "condition ? when_true : when_false" construct. Haven't actually made the string preprocessing though.

Message 3 of 6
(3,767 Views)

Hi Erik,

 

I think you didn't see the date of this post..:) anyway, good job..kudos to u..;)


Regards,


Nitzz

0 Kudos
Message 4 of 6
(3,765 Views)

As another followup, many years later, the Parse Formula Node and Eval Parsed Formula Node pair still doesn't support Min, Max, and a few other functions, nor Boolean logic. According to Rolf Kalbermatter (Hi, Rolf), there are other issues with these old VIs. Maybe the MathScript node is the way to go now, as long as you want to install MatLab. Has anyone updated the Formula VIs, or come up with any other way to allow RUN-TIME editing of a formula, maybe scripting a formula node, or other clever tricks? I didn't find anything on OpenG.

0 Kudos
Message 5 of 6
(3,328 Views)

@MegKB wrote:

Maybe the MathScript node is the way to go now, as long as you want to install MatLab.


The MathScript node does NOT need Matlab.  It runs Matlab-like code, but it is totally inside of LabVIEW.  There is a Matlab node that uses ActiveX to run Matlab.  For that you need to have Matlab installed.


GCentral
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
0 Kudos
Message 6 of 6
(3,310 Views)