Formula node, condition

I want to use conditional expressions such as
if () then
statement
else
end if
in the formula node, but there were error messages "unassigned output".
I followed Ankita's suggestion to use
if (x<5)
y=4;
z=8;
else
y=8;
z=4;
but there were same error messages(I tried "end if;" also.).
Thanks.

Which version of LabVIEW are you using? Any chance it is earlier than 6.0?
If so, then Ankita's suggestions probably won't work, because there were major changes in Formula Node behavior. I recall that every variable introduced in pre-6.0 formula nodes had to be explicitly added as either an input terminal or an output terminal on the formula node. Furthermore, those older formula nodes used a different style for conditional syntax. It's all documented in the manuals or help documentation that shipped with your LabVIEW version, whatever that may be.
More to the point, I suggest that you abandon the formula node for simple conditionals like this and just use a case statement. You can wire your x variable into a less-than node, then wire the output of that into a case statement selector. You can very often avoid formula nodes by using case statements or even the "Select" node on the Comparison palette.
My two cents,
John

Similar Messages

  • Formula node conditional

    Hi Guys
    I wrote a simple conditional code in formula node and there is no error but it doesn't calculate. It works wrong and when I check the code I can't find any mistake.Please read my code and Let me know what is wrong with my code.
    Thanks so much
    Solved!
    Go to Solution.
    Attachments:
    watt.vi ‏7 KB

    It's fairly clear you are a text-based programmer. You should learn to do things the LabVIEW way. Here is your formula node code written in LabVIEW:
    Note that you should NOT perform a direct comparison to zero with floating point numbers. This issue has been discussed MANY times in this forum (example search) and has nothing to do with LabVIEW, as it is an issue with the way numbers are stored with computers.
    Attachments:
    the LabVIEW way.png ‏21 KB

  • How can I programatically perform a conditional formula in "Eval Formula Node"?

    Okay, I'm stumped. I have an application where I need to evaluate a conditional programatically, and I can't do it with a Formula Node.
    Basically, my user wants to be able to enter some formula which describes conditionals, such as "if this temperature goes above X degrees or this temp goes above Y degrees, then take a reading" kind of thing. Since the conditional will be saved in a file, the formula node needs to be dynamic.
    I've used the "Eval Formula Node" before, which is built for this type of application...sort of. I tried it, but after trying in vain to get it to work properly, found out that it doesn't do boolean and conditionals in its parser, so it won't work.
    Does anyone
    have a good idea how to do this??

    Why do you even want to use the formula node at all? I don't think you "can take a reading" (i.e. interact with hardware) inside a formula node anyway.
    The formula node allows conditionals, see e.g. the example in the online help (image attached).
    You could also use a case structure with seperate formula node in each case.
    I highly prefer to skip the formula node and use wires instead. It will be more efficient and also much easier to debug. A formula node is not "in the true spirit of LabVIEW" ;-)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FormulaNode.gif ‏2 KB

  • If-then statement in formula node

    **Note - The attached file shows the current block diagram.
    I have a formula node inside a for loop. Inside the formula node I am trying to program the if-then statement:
    If T1<2.0E-5 OR T1>5.5E-4 THEN GOTO 3
    U7=U7+V
    I have 4 items I need help with:
    (1) Is 'II' the correct operator for 'OR'?
    (2) Is 'goto' an acceptable operator within LabVIEW?
    (3) 'U7' is building a 1D array. How do I need to define it? Is it simply 'int U7'? Also, I will add an output value named 'U7' on the formula node wall with an indicator wired to it from outside the for loop.
    (4) Is my use of the equal sign appropriate or do I need to use '=='?
    Thanks for the help.
    Philip
    Attachments:
    if-then_in_FN.jpg ‏18 KB

    Thanks for the help. I went ahead and rewrote the program so I could omit the 'goto's. Another problem that I am having is that I want 2 statements for 1 assignment:
    if (T1>=.002004 && T1<=.002584)
    B1=U
    A1=V;
    I want to assign both B1 and A1 values when the above condition is true. I tried a comma between the U and A1 but it doesn't work as well. Should I define A1 and B1 separately? Or would this create problems?
    if (T1>=.002004 && T1<=.002584)
    B1=U;
    if (T1>=.002004 && T1<=.002584)
    A1=V;
    Thanks,
    Philip

  • "Eval Parsed Formula Node VI" does not return outputs in predefined order

    I make a data analysis program, where the data consists of some million events and each event has e.g. 4 channels and 1-5 hits on each channel. 
    I would like the user to select different expressions of these channels to give coordinates to plot in a 2D histogram (increment a bin in Intensity Graph), e.g. for some experiment you want to show x=ch1-ch2; y=ch1+ch2+ch3+ch4; while in another experiment you want x=ch1-123; y=123-ch2;
    There are other VIs that use static LabView-code for the normal things, but now after a few years of adding to this program I find that it would be quite good with a general plotter and let the user specify simple expressions like this. Also with the "normal" static plots, there is a need to filter out bad data and then it would be much simpler both to program and use if you could write text expressions with boolean logic to combine multiple filters. Making a LabView code and GUI that allows AND/OR/parenthesis combinations of expressions will be quite an effort and not very reusable.
    So, with the above motivation, I hope you see that it would make sense to have a useable string formula evaluator in LabView. I find some info about MathScript's user-defineable functions, but haven't managed to get MathScript working in LV2010 yet (maybe some licensing or installation issues, I think I had it in 8.6). But I think it would be possible to do most of what I want for the display-part (not the filtering) with the simpler Eval/Parse Formula Node VIs and suitable use of the limited variable name space. So I started testing, and found a quite annoying issue with how the evaulator works.
    To the parser, you are expected to send an array of output variable names. But then it ignores this array, and returns one output per assignment/semicolon in the formula, in the order of the formula text. Since the static parts of my program need to know what the output values mean (which of them is x and which is y), I would have to rely on the user not using any intermediate variable and defining x before y. The attached screenshot demonstrates the problem, and also that it has been solved by NI statff in the "Eval Formula Node VI" which does the appropriate array-searching to extract only the pre-defined outputs, in their expected order. But using that VI is about 100 times as slow, I need to pre-compile the formula and then only use the evaulator in the loop that runs over a million events.
    I don't know if I'll take the time to make my own tweks to the parsing stage (e.g. preparation of array-mapping to not have to repeat the search or maybe hacking the output list generated by the parser) or if I'll have to make it in a static Formula Node in the block-diagram (which supports more functions), so that the user has to run with development environment and stop the program to change the plotting function. But I wanted to share this trouble with you, in hope of improvments in future LabView versions or ideas from other people on how I could accomplish my aim. I have MATLAB-formula node possibility too, but is far as I have seen the only place the user could update the formula would then be in a separate .m file, which is re-read only when typing "clear functions" in the Matlab console window. (Having this window is also an annoyance, and perhaps the performance of calling Matlab in every iteration is not great.) 
    Besides this issue, it also seems very strange there is virtually no support for conditional expressions or operators in Formula Node evaulated formulas (called Mathematics VIs in the documentation). Maybe using (1+sign(a-b))/2 you can build something that is 0 when a<b and 1 when a>b, but it is not user friendly! Would it really be diffcult to add a function like iif(condition, return_value_if_true, return_value_if_false) to replace the unsupported "condition ? if_true : if_false" operator? Would it really be difficult to add support for the < <= >= > == || && operators? Although compiled to an assemply language, this can't exactly be difficult for a CPU.
    Attachments:
    LV script test.png ‏62 KB
    LV script test.vi ‏18 KB

    (1) You can put any kind of code inside an event structure with the limitation that it should be able to complete quickly and without user interaction.  For example a while loop for a newton-raphson method is fine, but an interactive while loop where the stop condition depends on user iteraction is not recommended. By default, event structures lock the front panel until the event completes, so you would not even be able to stop it.
    (2) Yes, you can do all that. LabVIEW has no limitation as a programming language. Use shift registers to hold data and state information, the manipulate the contents as needed.
    (3) I would recommend to use plain LabVIEW primitives instead of formula nodes. Show us your code so we can better see what it's all about. Obviously you have a mismatch betweeen scalars and arrays. It is impossible from the given information where the problem is.
    (4) Yes, look inside the nonlinear curve fit VI (you can open it an inspect the code!). One of the subVIs does exactly that. Just supply your model VI.
    LabVIEW Champion . Do more with less code and in less time .

  • 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.

    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!

  • Why do in-line conditiona​l expression​s work in Formula Node but not in 'Eval Formula Node.vi'?

    'Eval Formula Node.vi' and a standard Formula node seem identical in most respects in terms of their functionality, however I'm stumped by the case of inline conditional expressions. 
    I'd like to read in a string in the syntax "(expr)?(expr)expr)" from a text file and recieve the output as a double.
    The subVI seemed like the perfect tool since I was already using it to interpret a number of other calculations within the text file, however in this case the behavior is not as expected.
    Has anyone else ever tried this? is there a different syntax needed between the two tools?
    Are there other features of the Formula Note not replicated by this VI?  (so I can avoid them in future)?
    For simplicity I've attached a little demo of the behavior.
    I am currently working in 2010, which I know is getting on in years.
    If the behavior is improved in later versions, that may be a good excuse to upgrade :-) 
    Thanks,
    Elaine R.
    Attachments:
    Conditional Formula Node demo.vi ‏13 KB

    .aCe. wrote:
    Eval formula Node does not do any conditional expressions as far as I am aware.
    That is right. It's a rather dirty hacked VI library to do some formula evalution and has many limitations in comparison to the Formula Node including no support for conditional operator as well as some others. In addition it can also error on some more complex bracketed expressions.
    It is an old example VI that was never revisited and probably never will be as writing a new one from scratch would be easier. But considering that the Formula Node and Mathscript and other possibilities exist, this is not likely going to happen soon.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Dead loop in formula node

    Hi,
    I have encountered the following problem in a formula node. Everything seems simple and right. But there is no output and the loop goes on forever. The sizes of both input arrays are the same. Need your advice. Thanks.
    Rut
    Attachments:
    Algorithm.vi ‏11 KB

    Look, I am far out on a limb here, because I am not a C programmer. Whatever you're doing would make more sense from a FORTRAN point of view.
    The LabVIEW formula node uses BNF notation (check the help), which is in many ways C like. So the syntax for a FOR loop is:
    for ( InitExpression ; CondExpression ; LoopExpression ) Statement
    This means the loop iterates until "CondExpression" is true.
    Do a google search on "C For loop" and you might find for example pages like:
    http://www.hitmill.com/programming/cpp/forLoop.htm
    http://www.geocities.com/learnprogramming123/Clesson8Beginner.htm
    Your condExpression is "n1-1", which, during the execution of the node is a constant. For example if you array size is 50, n1-1=49, FOREVER! The condition is never true so the loop will never stop.
    I hope somebody more knowledgable will chip in at one point.
    LabVIEW Champion . Do more with less code and in less time .

  • Formula Node result of NaN

    Hello to all,
    I have done a Formula Node with the next formula:B=(2*16/3.14159*(asin(sqrt(V/Ab))-3.14159/4))-(2*16/3.14159*(asin(sqrt(Uoffset/Ab))-3.14159/4));
    Ab=3.269.
    V is the data entry to the formula node.
    Uoffset is the mean of the 100 first values of the data that I obtain it previosly.
    I know that I can not do the square of the negative number and the asin I can not do it for values greater than 1 for that reason I don´t put values greater than 3.269 into the V value never and negative values either.
    I take this precautions but I obtain several times the output value of NaN I use the entry V for example:0.00061035 could be that the format of the entry it is very extends.
    Also when I introduce the same data to this formula, one times I obtain some values in the out and when I execute the subVI with the same data I obtain other values in the out.  Said it diferently I obtain different out for the same data in. How it is possible????
    The other hand I need to do the integral and the derivate of one array, how can I do it??? And the more important how I can or what I use for the parameter dt of the derivate???
    Thanks a lot
    Gonzalo De Francisco Ortiz

    Hi Gonzalo,
    after having a first look: You have a race condition in your code: why do you use a local for the mean value instead of simple wiring?
    I think that's the reason for your unexpected results!
    Other small items:
    - when you use auto-indexing you don't need to provide 'num of iterations' to the for-loop.
    - the only difference between the 2 cases is the 'abs'-function used for negative inputs. Just do the 'abs'-function everytime and you don't need the case-structure...
    - when testing numbers against zero you can use specialized functions from the comparision palette
    Editing:
    I attached a changed example in LV8.0
    Message Edited by GerdW on 02-01-2007 01:22 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    FormulaNode.vi ‏20 KB

  • Formula Node (Numeric Comparision by using AND, OR functions)

    Dear All,
    I want to compare my input if it is in the range of/between 0.00 and 0.5 it should return/output 0.5, how i can do this in Formula Node.
    e.g
    If (x>=0 and X<=0.5)
    y=05;
    if (x>0.5 and x<=1)
    y=1;
    if (x>1  and x<=2)
    y=2;

    Hello M.
    As long as your logic does not get much longer I would recommend a conditional evaluation like
    y =
    (x>=0.0 && x<=0.5) ? 0.5 :
    (x>0.5 && x<=1.0) ? 1.0 :
    (x>1.0 && x<=2.0) ? 2.0 : -1;
    I hope you like it, Guenter

  • How a can restar all my variables of some "Formula nodes"?

    I have one formula node with several outputs,
    I want restar one of her value to 0 when one sentence is false o is true.

    I am not quite sure what you are wanting to know. I suspect that you want to be able to write if-then statements (conditional ) in the formula node. The best place for this kind of information is to right click on the boarder of the formual node >> help.
    I dug around for a few seconds and found the following cryptic information:
    The numeric value of TRUE is 1, and FALSE is 0 for output. The logical value of 0 is FALSE, and any non-zero number is TRUE. The logical value of the conditional expression
    is if the logical value of is TRUE and otherwise.
    I think this means if is true then do otherwise do
    There is an example that might be more helpful. Open LabVIEW >>
    help >> find examples >> click on search tab >> look for formula >> open calculate volume.vi .

  • Usage of formulas in conditions in BEx Query Designer

    Hi guys,
    does anybody of you guys know, if it's possible to use the results of formulas in conditions? I tried it, but the result of the query was "No applicable data found", but there are data for the selection.
    When I'm defining the condition with the key figure (no restricted or calculated key figure), then the query can be executed.
    In my case, I like to define a condition based on a formula result. The value should only be displayed, when the result is greater than 30.
    Any ideas or are there any bugy in the BEx Query Designer?
    Thanks a lot + best regards,
    Clemens

    Hi Clemens,
    I have created a condition in my own system based on formula and it works perfectly fine. Please check following points in your condition change mode,
    1) Condition is marked as Active.
    2) In the block "Evaluate condition below for" you will have to select "All characteristics in drilldown Independently". If you have selected combination of characteristics then you will have to maintain proper sequence otherwise your condition will not work.
    3) In the next block when you set the condition, click on new, in the first block select your Formula from dropdown and set the proper operator in your case you will have to select "Greater than" in the next column set the value of key figure and just trasnfer it.
    Now you are ready to use the condition.
    Regards,
    Durgesh.

  • IF statement in Formula Node

    I have the following statement in a Formula Node in LabVEW 7.1:
    if (x=1) y = 3; else y = 1;
    When running the VI, whatever the value of X is, I obtain Y = 3 !!!!
    Why ???
    Tom

    Try x == 1 (instead of x = 1).
    Using LV8.0
    Don't be afraid to rate a good answer...

  • Can I use a formula node to start the execution of a case structure?

    Hi,
    I am working on editing a VI to make it much easier to understand (for colleagues and non LV users). For one reason or another, the VI's creators did not fully make use of the power of case structures and other structure types. In the application we need it for, the instrument cycles and repeats measurements on several objects. We are interested in measuring the motor currents for several motors in the system. As it stands now, for each sample object's run, there is a separate sub-vi diagram which displays its waveform trace and several indicators such as max current, time at max, etc. That code was contained within a T/F case structure and copied and pasted 20 plus times.... Obviously the vi became extrememly cluttered and needed a huge screen to see. The trigger for the current case structures is an EQUALS comparison between one input (which is the sample object counter; and this part I will likely leave unchanged since it makes a lot of sense already) and a constant which was defined 1 through 20+ for case. 
    I have since made one case structure and 20+ instances of that case and have labeled them (at the top selection box near the detent arrows) "1", "2", 3, etc. I am wondering if I can use a formula node to act as the "trigger" which sets each case structure running? I believe that a simple IF statement should work. Please see a snippet of my attempt at making this in C below.
    For the node, I defined X as the input and Y as the output. The input to the node, X, is connected to the sample object counter. The output, Y, is connected to the case selector of the case structure. My attempt at the code is below:
    int32 y
    For(x == 1)
       y = "1";
     For(x == 2)
       y = "2";
    etc, etc.
    Is that above code snippet correct? Do i need something like "ENDIF" or "end if" at the end? Does "y" have to be defined as "int32" or can it be something else?
    Thanks for the help!

    Is your formula node doing anything else besides what is shown?
    Why don't you just wire the value that is going into it at X directly into the selector of the case structure?
    Attachments:
    Example_VI_BD.png ‏2 KB

  • How do I get an array output on a Formula Node?

    My problem is simply that I cannot figure out how to get an output on a Formula Node to be an array. Documentation states that "you must declare local arrays and output arrays in the Formula Node" but doesn't say anything more than than. Attempts to put something like "float32 out[100];" for an array output called "out" fail.
    If anybody knows how you can do this or even knows if it is possible I would appriciate your help.
    Thanks,
    Naveen

    I found a typo in the formula node I was doing that was making the output not be an array. I don't think I was getting the error before but I was going to put together an example VI to attach here and I found it. So, thanks for your help even tho it was a stupid little mistake on my part.

Maybe you are looking for

  • .mov won't open in Quicktime

    Hello all. I have a strange issue with a .mov file. It is visable to me in the Finder preview window (i.e. I can press the play arrow and watch the movie and hear sound), but when I try to open it with Quicktime X, Quicktime 7, FInal Cut, etc. I get

  • Burning CD's works fine, BUT when playing the cd, seconds are being skipped

    Hi, Burning CD's works fine here, but when I play the completed CD, every 30 seconds a second of the song is being skipped. It's like it jumps one second forward. Any ideas for this problem? I already tried to solve it by rebooting and burning the pl

  • SDN - Wiki - Add page permission

    Hi, I wish to add a page in ABAP Development and Programming area, but it says that "You dont have permissions to add pages in this topic". Instead the topics which are not relevant to my domain are permitted. What should be done ? Please advice. Reg

  • Deleting used emails?

    Does anyone know how to delete used emails addresses? Say for instance I emailed someone but don't want the email address to show up when I begin to type another email much like the other, or if someone changed their email and I type there name both

  • Using my (signed in) google page as my home page

    I use Windows XP and until recently when I started Firefox it remembered my choice and the homepage was my (signed in) Google home page. There have been Firefox and Google updates (which may be irrelevant) but now I get a page which is suggesting I t