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 .

Similar Messages

  • For loop in formula node

    Hi,
    I wanna do some signal processing after I got the magnitude and phase infos from FFT. But the errors say that there is undefined variables.  I am just wondering that here absP and angleP are both vectors. Can I express them like what I did in the attached vi? 3x.
    Huihui
    Attachments:
    Untitled 12.vi ‏9 KB

    Hi huihui,
    do you just want to know the real and imaginary values of your signal?
    Why use formula node at all?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Untitled 12.vi ‏13 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 .

  • Formula node

    Hi everyone.
    I have a problem with the formula node.
    I want to calculate the following  function:
    Ux=xdot+Omegat*(y-y0)+thetax
    where xdot, Omegat, y, thetax are all 1D arrays ( honestly these are waveforms but I convert these in arrays) while y0 is a constant. Also the output Ux has to be a 1D array.
    When I implement the formula in the appropriate box I receive a message about
    "array indexing indices".
    For more information I link my .VI.
    Some idea how to solve this task?
    Second question:
    Using the formula node is faster than realize all these operations in a
    different way?
    I ask it because I will need to include this .VI into 5
    different "for loops"?
    Thanks
    matomato
    Attachments:
    formula node.vi ‏87 KB

    Hi matomato,
    fastest is usually to use LabView primitives! See attachment...
    Edited: made another small change to your vi: changed y0 to DBL to avoid unneccessary datatype conversions!
    Message Edited by GerdW on 02-27-2008 05:11 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    formula node1.vi ‏87 KB

  • How do I determine array size in a formula node

    I am feeding an array into a formula node to perform an operation on. However the size of the array can be an arbitrary size. How can I determine its size to use for iterating through a for loop?
    I suppose that I could add another input that is fed with the array size from the array palate but I would like to know if it can be done inside the formula node itself.

    Your own advice is the only and best one.
    greetings from the Netherlands

  • Want to learn more about shift registers and formula nodes

    I am new to Labview and have looked at the example files and help files regarding shift registers and formula nodes. I was hoping that someone has a simple and detailed VI expaining how each of them(shift registers and formula nodes) works.

    Formula nodes are not one of the first things you will need to be looking at. look at the help files (press ctrl-H) for some syntax examples. Shift registers are easy: they carry the value from the end of the loop back into the start of the loop. The great power of shift registers is to use them without initializing. In that case they will retain their last value as long as the vi is in memory. This is a little more advanced topic, though.
    I included a simple example that illustrates what a shift register does. Requires Labview 7.1
    Good luck,
    aartjan
    Attachments:
    shift (LV7.1).vi ‏19 KB

  • Formula Node Calculation Issues

    I'm trying to make an array where the output is defined by the formula 25*(2^x) where x is the input variable, with integer iterations from 0 to 7.  To do this, I made an formula node and put it in a for loop.  Unfortunately the (^) symbol is not working right for the calculation.  I tested it simply with x^2 and this did not work, while having x*x returned the correct values.  Instead of outputting the correct values, it outputs seemingly random integers.  Anyone know why?  I am new to this software so I apologize if this this a common issue but I could not find help anywhere else.
    Solved!
    Go to Solution.

    If you use the numeric primitives rather than a formula node, craziness can be avoided (well, sometimes).
    Lynn

  • Array output from formula node

    How to get an array output from the formula node.I am trying to use a for loop inside the formula node and want an array output.

    You cannot place a For or While Loop inside the formula node.
    Here is what the Help Description says about the syntax inside the Formula Node:
    Formula Node
    Evaluates mathematical formulas and expressions similar to C on the block diagram. The following built-in functions are allowed in formulas: abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, cos, cosh, cot, csc, exp, expm1, floor, getexp, getman, int, intrz, ln, lnp1, log, log2, max, min, mod, pow, rand, rem, sec, sign, sin, sinc, sinh, sizeOfDim, sqrt, tan, tanh. There are some differences between the parser in the Mathematics VIs and the Formula Node.
     Place on the block diagram
     Find on the Functions palette
    Refer to Creating Formula Nodes and Formula Node Syntax for more information about the Formula Node and the Formula Node syntax.
    Note  The Formula Node accepts only the period (.) as a decimal separator. The node does not recognize localized decimal separators.
    <SCRIPT type=text/javascript>if (typeof(writeVarRefs)=="function"){writeVarRefs("763");}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvrthelp763) != "undefined"){document.writeln(lvrthelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvfpga763) != "undefined"){document.writeln(lvfpga763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvemb763) != "undefined"){document.writeln(lvemb763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvpdahelp763) != "undefined"){document.writeln(lvpdahelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvtpchelp763) != "undefined"){document.writeln(lvtpchelp763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvblackfin763) != "undefined"){document.writeln(lvblackfin763)}</SCRIPT>
    <SCRIPT type=text/javascript> if(typeof(lvdsp763) != "undefined"){document.writeln(lvdsp763)}</SCRIPT>
    Example
    Refer to the Create Function with Formula Node VI in the labview\examples\general\structs.llb for an example of using the Formula Node.

  • Sine square function in formula node

    Hello
    I need to generate a function
    I = Iz * sin^2(B)
    where B = (pi/2)*(V/70)
    Iz = 0, 0.1, 0.2, 0.3 ... 1.0
    V = 1,2,3 ,4...135
    I tried to do thi sin formula node. but cud not get it.
    See attchment.
    Nghtcwrlr
    ********************Kudos are alwayzz Welcome !! ******************
    Attachments:
    Sine square in formulanode.vi ‏18 KB

    This will not work. B has 105 elements, and IZ has only 10. B and IZ must have the same numers of elements. And you should perhaps use a for loop not a formula node
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)

  • Changing Output type in Formula Node?

    I looked at some other posts on how to set a formula node output as an array, and am unsure why it is not an array. Here is the text in my node: ("out", "in1", and "in2" are all supposed to be 2D arrays; i is an int)
    int32 out [50][50];
    if (i==0)
    out = in1;
    else
    out = in2;

    Hi,
    you must use something like
    int32 out[50][50];
    int32 j, k;
    if (i==0)
    for (j=0; j<50; j++)
    for(k=0; k<50; k++)
    out[j][k]=in1[j][k];
    else
    for (j=0; j<50; j++)
    for(k=0; k<50; k++)
    out[j][k]=in2[j][k];
    I think this is because formula node must be precompiled before execution of your VI. In your case it doesn't know how to address different array elements of "in1" and "in2" because it doesn't know its sizes before you start your VI. In my example I specify the adresses of array elements by using indecies [j][k].
    In any case it looks like you can't make direct assignment of arrays like "arr1=arr2". You always must assign its elements in a loop like "arr1[i]=arr2[i]".
    Good luck.
    Oleg Chutko.

  • Formula Node & Array Operations

    Hello,
    I'm trying to use the formula node to subtract the previous term from the current term (or the next term minus the current term), but I can't figure out how to
    use the array index to do it. 
    I've something along the lines of z_array[i+1]-z_array[i], but it only returns the difference of i+1-i....
    Please see the attached picture.
    Thank you,
    Solved!
    Go to Solution.
    Attachments:
    Formula node.JPG ‏23 KB

    That would be so easy to do in pure Lv code.
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • 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 with global variable

    Hi,
    I am tring to use formula node with global variables as an input and output,
    but this is where I see the SW hangs forever.
    By the way I am a novice to the labview.
    Can some give me hint why this is happening?
    Thank you in advance,
    Do
    Solved!
    Go to Solution.
    Attachments:
    formula_node_wGlobalInputOutput.JPG ‏281 KB

    Well, the first case of the two loops has a direct LabVIEW translation like this:
    However, just because that's the direct translation doesn't mean that's what you should be doing. In the formula node it seems as if you were copying elements from one array to another. Element-wise operation on arrays via loops can be quite inefficient in LabVIEW. Often one can operate in place with arrays, and an operation that would require two loops in a language like C would actually require no loops in LabVIEW. In fact, with the above example, even if you were to use loops, arrays can auto-index for-loops so you don't even need to wire the constants to the N terminals to tell the loop(s) how many times to run.
    Can you describe what you're trying to accomplish? There's likely to be a more natural way to do it in LabVIEW that would require no loops. Have you gone through the tutorials? You can also look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

  • Formula Node: Array Size can be specified by wiring an input ?

    All
    I have a formula node where I have a module which operates on an array. I want to keep the size of the array generic. So I tried keeping the array size as an input N, and initialized the array as xdim[N]. It shows an error in my formula. what am i doing wrong ?
    Kudos always welcome for helpful posts

    I had exactly the same issue as Spartan00.
    Just for curiosity, I was comparing labview speed in initializing a gaussian array through both the normal graphic code and the formula node.
    The formula node proved to be MUCH, MUCH faster.
    float m = 0.5, s=0.5, x;
    int i;
    float y[1000000];
    for(i=0; i<1000000; i++) {
    x=i*1e-6;
    y[i]=exp(-pow((x-m),2)/(2*s));
    Unfortunately, I can't wire the array size as an input.
    (By the way, I simply enclosed the formula node in a for loop and let it run 10000 times to get the average execution time. I did the same for the equivalent graphical code and it turned out to be much slower).
    Has anybody ever tried to do the same?

Maybe you are looking for

  • My MacBook Pro is running very slowly! Please help!

    Hi all, as of late last year my MacBook Pro started running very slowly. As I'm a novice when it comes to computers I thought I'd turn to the interweb for solutions. I've tried a couple of basic things but don't seem to be getting anywhere.I ran the

  • How to hide Saved Searches in the header area of web ui

    Hi All, My Query Is how to hide Saved Searches in the header area of web ui. For This is there any configuration or we have do through the code. Thanks & Regards, Venkat

  • Audio stream gets reset when it shouldn't

    Hello I've got 1 asset with 4 audio streams and 5 subtitle streams and according to the language choice made on the first page of the menu, the correct audio streams and subtitle streams get set. There are 10 different documentary DVDs, of these 5 ar

  • Difference between N-80 latest two updates?

    hey guys, can anyone tell me what are the differences between the latest two firmware updates for N-80 V4.0623.0.41 & V4.0623.0.42 did anyone notice any changes? when I tried to update over the air from V4.623.0.41 it was showing that there are no up

  • How to play FLV at its native resolution?

    I am using an embedded Flash player set to display FLV files by default at 422x317.  When I click the player's max button (lower-right corner), the player maximizes so that it fills the entire monitor, which is sometimes set to 1920x1200 and sometime