LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Impelement for loop and do while loop

I'm currently trying to implement the following software code into labview,

For(i=0,i++,i<200)
{
buffer1[i]/count = temp;
while (temp>360)
{
temp = temp - 360;
}
buffer2[i]= temp;
}

buffer1 and buffer2 ==> 1D array of size 200.
temp ==> temporary variable (used in this routine only)
count ==> global variable(calculated in another routine)

i'm really very loss with trying to convert the above code into labview. things like

1. how to implement the temporary variable?
2. how to store the data into the buffer2?
(eg: first data will go into buffer[0], follow by buffer[1], and so on.)
3. how to implement the while and for loop that suit this application?
4. how to implement the temp = temp -
360 ??

i have been trying for days, but having no progress. help!! help!!

very lost lyn
0 Kudos
Message 1 of 9
(3,655 Views)
lyn wrote:
> I'm currently trying to implement the following software code into
> labview,
>
> For(i=0,i++,i<200)
> {
For loops are easy....

> buffer1[i]/count = temp;
.... but what are you trying to do here ? Do you mean "temp=buffer1[i]/count"
?

> while (temp>360)
> {
> temp = temp - 360;
> }
Rather than subtracting 360 from temp until it is less than 360, could
you not use the mod operator ?


> buffer2[i]= temp;
> }
>
That is easy to, since all this goes in a for loop, you may be
best off using the auto-indexing feature of loops. Look in the
help for info about using it.

> 1. how to implement the temporary variable?
It'll probably end up as a connection between two components.

> 2. how to store the data into the buffer2?
> (eg: f
irst data will go into buffer[0], follow by buffer[1], and so
> on.)
Autoindexing is your friend.




--
Remove "spamkill." when replying to this message
0 Kudos
Message 2 of 9
(3,655 Views)
The key is to understand data flow... I have attached some example solutions, the solution depends on how you calculate the count value.
0 Kudos
Message 3 of 9
(3,655 Views)
Send me your email adress and you get the vi (I can't post with an
attachment, don't no why).

Niko
0 Kudos
Message 4 of 9
(3,655 Views)
thks Niko,

i'm email address is ferlynchua@hotmail.com

lyn
0 Kudos
Message 5 of 9
(3,655 Views)
I'm sorry Dave, what does you mean by mod operator? I still dun understand how to implement the

while(temp>360)
{
temp = temp - 360;
}

as the temp is a temporary variable, and i'm required to update this new temp value for the test condition(while loop)??

and also what does you mean by " a connection between two components"?

thks,lyn
0 Kudos
Message 6 of 9
(3,655 Views)
Have you downloaded the examples I sent yesterday? I'm quite sure they answer the questions...
0 Kudos
Message 7 of 9
(3,655 Views)
Hi Mad,

I have tried the vi that you had given me, but it was still not i required exactly.

For(i=0, i++, i<200)
{
temp = buffer1[i]/count;

while (temp>360)
{
temp = temp - 360
}
buffer2[i] = temp;
}
i want the count be buffer[1]/360

1. i need to check the 200 data in the 1D array named buffer1, hence i want the for loop to run 200 times

2. the data can be in few hundreds or even thousands, but i want to keep them within 360 as i'm calculating the degree, hence i want the while loop to do the checking.

the vi that you had given me, can only execute the subtraction once but not until the data value is within 360. hence i ask how to do the following while loop again.

while(temp>360)
{
temp =
temp - 360;
}

sorry for the confusion, thks again
lyn
0 Kudos
Message 8 of 9
(3,655 Views)
Hello Lyn,

you don't need any for or while loops for your example routine. As an other poster said: you have to understand the dataflow. See attached example.

Best regards,
Gerd
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 9
(3,655 Views)