LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to program a C like pragraming in formula node?

I need to write a simple C like progarm in the the formula. The below is the program.

int x, i ;
float large;
large=a[0];
for(i=1; i<202; i++)
{
if(a[i]>=large)
{
x=i;
}
}
return x;


But Labview thinks there is an error in it. But I can not find the error.So, anyone can help me?
0 Kudos
Message 1 of 17
(3,990 Views)
There is no return statement for LabView function nodes. Instead of return, add an output to the formula node structure.
1. Delete the return x; statment.
2. Right-click on the right-hand border of the formula node and select Add Output.
3. Enter x in the output box.
If you haven't already, you also need an input for the a[] array.
1. Right-click on the left-hand border of the formula node and select Add Input.
2. Enter a in the input box.
3. Wire the array control (or function) to the a input.
With those simple changes, your formula worked fine.
0 Kudos
Message 2 of 17
(3,990 Views)
P.S.
But you don't need a formula node to do what you're doing. The Array Max & Min function from the Array palette returns the max and min and their respective indices.
0 Kudos
Message 3 of 17
(3,990 Views)
Thanks for your advice. But I need to know the 0.707maxvalue of the array, and also its index. Can you help me?
0 Kudos
Message 4 of 17
(3,990 Views)
And there is always an error" Formula Node: array indexing expected "
0 Kudos
Message 5 of 17
(3,812 Views)
Make sure you have an array wired to your formula node input a. Look at my earlier answer for notes on creating the input and wiring to it.
0 Kudos
Message 6 of 17
(3,812 Views)
Yes. I have finished all of those things. But the error is still existed.
0 Kudos
Message 7 of 17
(3,812 Views)
If you use a Formula Node, you need to do something like this.
int x, i ;
float large, large707;
large=a[0];
for(i=1; i<202; i++)
{
if(a[i]>=large)
{
large = a[i];
x=i;
}
}
large707 = large * 0.707;

Then you need to add Formula Node outputs for large and large707.
Note that I added the line large = a[i]; to save the new max to large.
If you use Array Max & Min, use the Multiply function from the numeric palette to multiply the max value by 0.707. Look at the LabView help for Array Max & Min.
Look at the attached example.
0 Kudos
Message 8 of 17
(3,990 Views)
> Yes. I have finished all of those things. But the error is still
> existed.

As stated earlier, you are reimplementing the Min Max node. There is a
built-in icon that does this for you that you might want to consider.
If you still want to learn what is wrong with your formula node, you
need to post the VI since saying that an error exists isn't enough to
debug a program.

Greg McKaskle
0 Kudos
Message 9 of 17
(3,812 Views)
Don't forget to initialize x=0 just in case a[0] is the max.

Les.Hammer@CompleteTest.com
0 Kudos
Message 10 of 17
(3,990 Views)