- Community Home
- :
- Discussion Forums
- :
- Most Active Software Boards
- :
- LabVIEW
- :
- Re: Parse formula in Labview

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

10-09-2017 09:42 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Labels:

I have a question. How to parse in Labview text string contains one formula and then use it with variables, functions, dlls etc. Iuse "Eval parse formula" function, but a want add to that my own functions like: "**Pcalc[a;b;c;..]name**". And I will use a, b, c variables, and "name" of function.

I did try that a few times, but can't do it.

10-09-2017 10:44 AM - edited 10-09-2017 11:45 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

We are mostly graphical programmers here, so I would like to ask "why???".

0Forest0 wrote:

... and then use it with variables, functions, dlls etc..

How exactly are you imagining that to work? What do you mean by "use it"?

Have you tried mathscript? LabPython? Python Integration toolkit? Gpower expression parser?

(Disclaimer: I am not really familiar with any of those)

10-09-2017 01:49 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Have you tried mathscript? LabPython? Python Integration toolkit? Gpower expression parser?

Exactly are you imagining that to work? What do you mean by "use it"?

No. I mean use only in Labview. User enter the formula and variables. Program parse the string and calculate results with that variables in a loop.

10-09-2017 03:50 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

0Forest0 wrote:

Have you tried mathscript? LabPython? Python Integration toolkit? Gpower expression parser?

Exactly are you imagining that to work? What do you mean by "use it"?

No. I mean use only in Labview. User enter the formula and variables. Program parse the string and calculate results with that variables in a loop.

Google "LabVIEW parse formula". I think you'll find some stuff you can use.

Bill

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

10-09-2017 06:01 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

No, you cannot declare and use a function in Eval parse formula. You'll need Mathscript for that (and MatLab). You can 'declare functions' by creating sub-vi's which you can call by parsing some text.

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM

"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."

"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."

Highlighted
##
##### Re: Parse formula in Labview

Options

10-10-2017 02:38 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I've made this, but it's customer proprietary.

It has it's uses, for instance, when you want to define a calculated channel based on used input (a formula). The custom functions make sense, an interpolate, PID, LUT function for example can be very convenient.

My solution was to use Dykstra's Shunting-yard algorithm. An absolute peace of beauty. And in principle very easy.

In formula parsing, there are some tricky parts, especially with ^ (something the eval from NI did\does wrong). 2^2^2^2 = 2^(2^(2^2)) = 65536, not ((2^2)^2)^2 = 256. ^ is the only right associative operator, and that is often overlooked.

I wanted to allow math on scalars mixed with arrays, scalars vs scalars, arrays to arrays and Booleans vs Booleans, etc. since invoking a formula on two arrays one element at a time is dreadfully slow. This is just a complexity. If you don't need that, you can do it in a few days.

LabVIEW Programming ((make LV more popular, read this)

10-11-2017 11:25 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

My solution was to use Dykstra's Shunting-yard algorithm.

It is may help. I'll look it up, when I have a time.

10-11-2017 01:17 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I also have done something like this for purposes of a calculated channel. My method was:

I used a variant attributes lookup table to store all of my current channel values by name... and then used [ ] around the channel name that was to be used as a variable. For example

[Temperature] * 1.8 + 32

I then put the formula string through a look with a regex looking for [ ], and when it found it I would pull that out of the string and replace it with a string value from my lookup table. I'd then feed this into the parse formula.

It won't interact with DLLs or act like a function like you had specified... but it will allow you to parse arbitrary text strings as formulas with variables on the fly.

10-11-2017 02:06 PM - edited 10-11-2017 02:24 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

wiebe@CARYA wrote:

In formula parsing, there are some tricky parts, especially with ^ (something the eval from NI did\does wrong). 2^2^2^2 = 2^(2^(2^2)) = 65536, not ((2^2)^2)^2 = 256. ^ is the only right associative operator, and that is often overlooked.

Excel and Matlab doing it also wrong (details).

However, the LabVIEW help says that exponentiation is right associative and some simple testing shows it to work correctly, __except for the formula parsing__. For example the Formula express VI and expression node give the correct result for right-association. (See image)

Obviously, the sentence (link) "The precedence of operators is the same for the Mathematics VIs as in Formula Nodes. Refer to Formula Parsing VIs for more information about specific Formula Parsing VIs." is __incorrect for exponentiation__.

(I have not investigated in details, but that should be documented and corrected).