Array index problem in formula node

dear friend
I'm trying to use formula node to solve a problem because I make this program using c at the begining.
It runs perfectly in turbo c, but somehow it doesn't work in the formula node.
I try to debug my source code, and I find that the formula node seems can't read the true value in
the array.
Here is the code in the formula node.
int32 i,j,k;
for ( i = 0 ; i < sopa; i++ )
 j = 1;
 ep[i][0] = pa[i];
 ep[i][1] = np[ep[i][0]][0];
 while ( ep[i][j-1] != exit )
  for ( k = 0 ; k < sonp ; k++ )
    if ( np[ep[i][j-1]][k] != -1 && (pc[ep[i][j-1]][ep[i][j]] + pc[ep[i][j]][exit] >= pc[ep[i][j-1]][np[ep[i][j-1]][k]] + pc[np[ep[i][j-1]][k]][exit] ) && (pc[ep[i][j-1]][np[ep[i][j-1]][k]] == org[ep[i][j-1]][np[ep[i][j-1]][k]] ))
      ep[i][j] = np[ep[i][j-1]][k];
  j++;
This is the part that I think the problem might be.
if ( np[ep[i][j-1]][k] != -1 && (pc[ep[i][j-1]][ep[i][j]] + pc[ep[i][j]][exit] >= pc[ep[i][j-1]][np[ep[i][j-1]][k]] + pc[np[ep[i][j-1]][k]][exit] ) && (pc[ep[i][j-1]][np[ep[i][j-1]][k]] == org[ep[i][j-1]][np[ep[i][j-1]][k]] ))
 ep[i][j] = np[ep[i][j-1]][k];
I state that "np[ep[i][j-1]][k] != -1" but I do get the value -1 in the array "ep".
Could someone tell me why I get -1 in the array?
I hope I can finally do it all by labview not using formula node,but array like "pc[ep[i][j-1]][np[ep[i][j-1]][k]] "
seems very hard to wire in labview. Could someone give me some good advices of doing this?
Thanks for your help

altenbach 已寫:
normanshi wrote:
 ep[i][0] = pa[i];                                          (A)
 ep[i][1] = np[ep[i][0]][0];                            (B)
...    if ( np[ep[i][j-1]][k] != -1 && ... )          (C)
      ep[i][j] = np[ep[i][j-1]][k];                       (D)
I state that "np[ep[i][j-1]][k] != -1" but I do get the value -1 in the array "ep".
Could someone tell me why I get -1 in the array?
I hope I can finally do it all by labview not using formula node,but array like "pc[ep[i][j-1]][np[ep[i][j-1]][k]] "
seems very hard to wire in labview. Could someone give me some good advices of doing this?
There are many possible scenarios to get a -1 in the ep output. For example if the -1 gets already written in step (A) or (B) at a certain index, and that index does not get overwritten in step (D). You are indexing all over the place! Is there some bounds checking on the array contents? What are typical inputs and array sizes?
I'm sure about that the -1 doesn't get already written in step (A) or (B) because ep[i][0] and ep[i][1] is fine. What really makes me confuse is that sometimes ep array has the value like this.
That means it does overwritten some value in step (D). The -1 should never be written into it because I have already state that np[ep[i][j-1]][k] != -1. Somehow I still get -1,and this is really strange! I'm indexing all over the place becuase I can't figure out a better way to achieve my requirement.
I think I should briefly tell you what I'm trying to do. In this program,I input some values which means the distance from one point to another. Then I use floyd's all pairs shortest-path algorithm to find all the shortest distance. Finally I want to find out the "shortest path". I mean like from point 4 to point 0,the shortest path might be like 4 -> 2 -> 1 -> 0, and what the formula node part do is trying to find out this "shortest path". Maybe you can give me some better advice of doing this, I have been thinking a better way to do it for about two months. I think I'm really not good at this.
I try to do it all by labview ,but again I get a strange problem. This time the ep[i][j-1] doesn't get the correct value. In the first time i=0 j-1=0 ep[i][j-1] = 1,but the second time i = 0 j-1 = 1 ep[i][j-1] = 0. This makes the "ep[i][j-1]!=exit" get the incorrect boolean value. The ep[i][j-1] should be 2,not 0. I try to use highlight to find if I make any mistake, but I can't one.This is the input and I put the labview program in attached file (temp4.vi).
Could you help me find out why this happened?
Thanks for your help altenbach!
由 normanshi 在 08-19-2006 10:06 PM 上編輯的訊息
Attachments:
temp4.vi ‏191 KB
ep.jpg ‏10 KB
input.jpg ‏9 KB

Similar Messages

  • HELP: Run-time array dimension in LabVIEW formula node

    I need to dimension an array at run time within a formula node as follows:
    int32 i,N;
    N = sizeOfDim(inputArray,0);
    float64 outputArray[N];
    for (i = 0; i outputArray[i] = myfunction(inputArray[i]);
    However, LabVIEW complains "Formula Node: index list expected". On the
    other hand, if I say
    float64 outputArray[1000];
    LabVIEW is perfectly happy. But that's not what I need to do! Is there
    an alternative
    way of accomplishing my goal?
    BTW, I've tried calculating N outside the formula node and then
    presenting it as
    an input with the same results. I've got a bad feeling that run time
    array dimensioning
    just isn't allowed.
    TIA,
    Hugh

    Can't you just use the Initialize Array function outside the formula node and pass that instead?

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

  • 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

  • Problema con formula Node

    Buen día,
    estoy trabajando con un programa que me ayude a leer el caudal de una bomba de agua, el problema que tengo es que la formula node no me genera ningun dato.
    Agradeceria su ayuda
    Adjunto los archivos
    Adjuntos:
    Pantallazo problema formula node.png ‏172 KB
    Prueba 4.vi ‏58 KB

    Hola alipio;
    Algunas recomendaciones para tu código;
    1. Trata de ocupar los datos apropiados; usas I32 y Double lo qu eocasiona puntos de coerción y hace que tu código sea menos eficiente
    2. No tiene caso tener conectada la misma salida a dos esstructuras de casos iguales; puedes en su lugar utilizar sólo una;
    3. Trata de no hacer dobleces inecesarios en tus cables
    4. En cuanto al fórmula node; x, g son entradas y h,y son salidas; por lo que x=h no tiene sentido.
    Si quieres emplear el valor de la iteración anterior, puedes también obtenerlo del shift register; algo así como en la imagen de abajo. 
    Ojo; el VI no esta completo pero puse parte de tu código ahí
    En el caso falso de arriba (donde estan los contadores) se iguala contador 2 a cero, al igual que en tu select)
    Si tienes duda de como usar estas funciones avísame y con gusto puedo pasarte las ligas de algunos tutoriales
    Exito en tu aplicacicón

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

  • Can I create array inside formula node

    I need to create and use array (multidimensional) inside a formula node. My LabVIEW version is 5.1.The input and output from/to formula node do not necessarily being array. Thank you.

    You need to declare a variable to be an array. To declare a multidimensional array of 32 bit intergers enter this:
    int32 VarName[x][y];
    Where x=1st dimension size (rows) and y=2nd dimension size (columns). You can then operate on this like you would an array in a text based language. Try the entering the example below in a formula node.
    int32 i;
    int32 y[5][2];
    for (i=0;i<5;i++)
    y[i][1] = x[i]+1;
    Where y is an output and x is an 1D array input.
    Hope this helps...
    Brian

  • PV cell equation error in formula node

    Hi! I am currently building a PV system simulation in LabVIEW with maximum power point tracking, and I'm trying to make this VI work using the formula node but I can't run it due to an "array indexing problem". The VI is based on the LabVIEW's toolkit for IV characterization using the equation for the PV cell current. I added the XY graph to graph the current and voltage from the equation. I'm really new to LabVIEW, so any suggestion will be greatly appreciated. I  have attached the VI I'm building.
    Solved!
    Go to Solution.
    Attachments:
    eqn_based.vi ‏11 KB

    Hi spectre,
    the formula not cannot calc with arrays the way LabVIEW does:
    (Check for correct computation against given formula...)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Hi, formula node

    Hi,
    I am confused now about the formula node. The labview begins with 0, so the angleP is from 0-1023, however, in the Mathscript the index begins with 1. So I should use index k not k-1. But when I use angleP(k) in the Mathscript, the errors says the indexs are out of bounds for the variable you specified cause angleP is from 0-1023.  So that is the problem--how to deal with the different index range problem.
    I tried to finish this mathematical problem in formula node but there is still error but I do not know where it is wrong. Can you help me to point out the problem in the formula node. Thanks.
    Huihui
    Attachments:
    21.vi ‏9 KB

    Hi,
    Thanks for your reply.
    The attach file 1 is the vi with Mathscript node. The quetion here is the Mathscript begins with 0 while the labview begins with 1. So I do not know how to get the first signal from angleP in the Mathcript. So I tried to use the formula node but there are still some errors. I changed the array expression with square bracket, see the attached file 2. The input signal is from 0-1023.
    For the problem of operating 1D array in 2D, I think it is ok cause I wanna produce a matrix with m 1D array with the length of 1024, m is the number of the rows and k is the number of the signal per row.
    What I wanna do is to get the magnitude and phase signal then do some mathematical calculation to get the real and imaginary parts.
    Thanks for your sincere help. I notcie that you are the kind person who replied my question before. 
    Huihui 
    Attachments:
    1.vi ‏327 KB
    21.vi ‏9 KB

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

  • Formula node help?

    I am new to Labview and I'm trying to calculate an area based on the a formula.  The error message says array indexing expected, but I don't have any arrays feeding into the formula node.  Does anyone know how I could fix this?  Here's a snapshot of the block diagram.  Thanks! 

    Check the width of the wire going as input to 'd'... that an array...!!
    It might contain just one element or may be multiple elements...!! So use 'Index Array' and convert it into a scalar value...!!
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Shift Register while Indexing Arrays in Formula Node

    Hello, 
    I am having trouble using the formula node while indexing my two arrays.  I keep getting "NaN" for my output array. I believe the problem lies within my shift register.  My guess is that for the first calculation there is not a PreviousAngle so that is why it is giving me "NaN."  For the first index I would like the value of the PreviousAngle to be 0. I am new to LabView and unsure what to do.
    Thanks!
    Christian Seymour
    Solved!
    Go to Solution.
    Attachments:
    Complementary Filter.vi ‏21 KB

    The shift register should contain 0 by default since you are using a double [if uninitalized, the shfit register takes the default value of the data type.  In this case, the default Double is 0], but you should explicitly initalize the shift register to a default value in most cases.
    To do so, right click on the "previous angle" shift register and select "Create constant".  This will create a Double value of 0 to fill in the register for the first calculation.
    If you need a number other than 0 to start, you can just change this constant.
    **Note:  This is a good habit to have.  Shift registers retain value as long as the VI is in memory.  So if you run this more than once, it will have the value from the last execution automatically!  This is usually unintended behavior for new LabVIEW users -- however you can sometimes take advantage of this feature in some applications and make it intended behavior
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • How can I increment the index of an array in a formula node?

    Hi,
    I need some help with the formula node. I need an array, that increment every iteration of the code in the formula node. I need it to save amplitudes.
    I thought i could do this with i++; i is the variable for my index.
    Martin
    Solved!
    Go to Solution.

    Hello,
    does it sound well to you ?
    @+
    Tinnitus
    ps: sorry posts mixed
    Message Edité par tinnitus le 12-15-2008 03:05 AM
    CLAD / Labview 2011, Win Xp
    Mission d'une semaine- à plusieurs mois laissez moi un MP...
    RP et Midi-pyrénées .Km+++ si possibilité de télétravail
    Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
    Don't forget to valid a good answer / pensez à valider une réponse correcte
    Attachments:
    inc_node.vi ‏6 KB

  • In formula node how to use array outputs

    someone has talked about this. but it is still a problem to me.
    no matter how i declare the variable, the output terminal keeps a scalar.

    You should be able to declare it using:
    int32 VarName[x][y];
    That should make an array of 32bit integers.
    See one of my earlier posts here: http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000EE2C0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0&USEARCHCONTEXT_TIER_0=0&USEARCHCONTEXT_TIER_S=0&USEARCHCONTEXT_QUESTION_0=array+formula+node&USEARCHCONTEXT_QUESTION_S=0
    Try copying the code that I posted into your formula node and see if you get an array out. Or try the example I attached with the same code in it.
    Let us know if you are still having trouble.
    Brian
    Attachments:
    ArrayFormulaNode.vi ‏23 KB

  • Problems with bit shift left in Formula Node

    Hi,
    Sorry but my English is not good.
    I'm trying to execute a bit shift left in the Formula Node, but the shift left is not working as I expected.
    uInt32 parametro[5];
    float32 valorAmostra;
    int16 indiceAmostra;
    uInt8 indiceResposta;
    int16 controle;
    int32 valor;
    int8 i;
    for(i=0; i<5; i++)
    parametro[i]=param[i];
    valor = parametro[5]<<16 | parametro[4]<<8 | parametro[3];
    controle = parametro[1]<<8 | parametro[0];
    indiceAmostra = (controle & 0x3FF);
    indiceResposta = (controle >> 10);
    valorAmostra = valor & 0x7FFFFF;
    valorAmostra = valorAmostra*(2.4/8388607);
    if((valor & 0x800000) == 0x800000)
    valorAmostra = valorAmostra*(-1);
    the input param array is of the type uInt8, as I saw in other topics that does not shift with uInt8,
    I copy the values of param array to parametro which is of type  uInt32, but still did not work.
    Testing the input param with the following values:
    param[] = {10,14,10,0,16}
    the valorAmostra returned is 0,00117188 when he should be 0,300003.
    Can someone help me please?
    Solved!
    Go to Solution.

    Portuguese:
    Olá,
    Existe um bug no LabVIEW para esta operação. Este bug deverá ser corrigido em versões futuras. Uma solução para esta situação é utilizar um int32 ao invés de um ulnt32.
    Qualquer dúvida por favor entre em contato.
    Obrigado.
    English:
    I investigated the problem you are having, and it turns out that it is a bug that has already been reported and documented. The work around for it is to use int32 rather than uInt32.
    Thanks.
    Luciano Borges
    R&D Engineer
    Pirelli Brazil

Maybe you are looking for

  • Can't sync / uninstall / reinstall BB DM v4.7 - Windows Vista error 1402.

    I am running BlackBerry Desktop Manager v4.7 on Windows Vista Business. I was having no problems with the program until I downloaded the update that was recently published (build 59, date of publication 2009-06-05, size 111Mb). I downloaded this upda

  • Select distinct value

    HI all DESC CLAIMS CLAIM_NUMBER NUMBER(10) VERSION          NUMBER(2) STATUS          NUMBER(1) to every claim_number can be 3 statuses 0/9/1 there must be at least 1 status Select CLAIM_NUMBER   ,STATUS  from claims order by CLAIM_NUMBER,STATUS CLAI

  • Issues in setting up demo data for MapViewer 10.1.3.1

    Hi, I downloaded the MapViewer Quick Start Kit from http://www.oracle.com/technology/software/products/mapviewer/index.html I also downloaded the Demo Data set. I started the OC4J instance and able to view the MapViewer admin page. I created the mvde

  • Replacing Xserve, how to deal with RAID5+0 array

    We're finally looking at replacing our 8+ year old Xserve, which has served us faithfully, with a new Nehalem model. The question is what to do about the two XRAID arrays that we have attached via fibrechannel. Both are fully stocked with 14 disks ap

  • Move Regions WITH automation data

    Here's my predicament, i am trying to cut out and entire verse from the middle of a song. many regions, many tracks, all with automation data. no matter how i do it (whether i go track by track and delete the regions inbetween and move the later regi