LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Incrementing a variable based on the condition

Solved!
Go to solution

Hello everyone,

 

 I am learning a Labview and have a question. I am reading a data from the file, then compare it with a random number that I generate. And if two numbers are equal, I would like to increment my variable.

 I was able to do it with a shift register, but I have to wait until my for loop finishes then I can see my  value.

 Is there any other ways to increment a variable ? Because, in later, I would like to terminate the for loop if my variable exceeds certain value for example 3.

 Here is my VI screenshot.Screen Shot 2018-04-18 at 12.49.23 PM.png

 

0 Kudos
Message 1 of 14
(6,457 Views)

There are boolean operators in LabVIEW. Terminate your loop when you click Stop OR your value exceeds 3.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 14
(6,447 Views)

Just put the Counter indicator inside the loop structure. That way the indicator updates every iteration and you can see the actual value on your front panel.

0 Kudos
Message 3 of 14
(6,446 Views)

Hi Paolo,

Thank you for your answer. Yes, I am aware of it, I don't have a problem regarding that.

 

My question is that, when I run my VI, my value (named as counter in my VI) shows a result when my loop iteration is completed. For example:

Data          Random Value

2                3

3                4

4                4

5                1

In above case, my value (counter) should show 1 since there are only one same value pair (4,4).

I see that result when my loop finishes, not in the time that I can see they are equal.

My question is then: is there any other method (except shift register) to increment a value depends on the condition is met or not ?

 

I hope it is clear more.

0 Kudos
Message 4 of 14
(6,439 Views)

Sorry, I did not read carefully your post.

shoffel is right, of course.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 14
(6,436 Views)

Hello,

Thank you for your answer. But I don't want to see the loop integration value.

What I want is that I want to increment a value if my data value read from the file is same as my random value.

 For example:

Data          Random Value

2                3

3                4

4                4

5                1

In above case, my value (counter) should show 1 since there are only one same value pair (4,4).

I see that result when my loop finishes, not in the time that I can see they are equal.

My question is then: is there any other method (except shift register) to increment a value depends on the condition is met or not ?

 

 

I hope it is clear more.

0 Kudos
Message 6 of 14
(6,432 Views)

Sorry if my answer was misread. What I meant is:
Your "Counter" indicator, which is outside the loop at the moment, can just be put inside the loop, for example after the case is executed. Then you will see the current value of your wanted variable.

0 Kudos
Message 7 of 14
(6,428 Views)

Hi Schoffel,

 

 Thank you for your message. Yes, your solution is valid for seeing it in the same time.

But the problem the counter value will back to zero. For example

 

DataValue        RandomValue       Counter Value

4                       4                           1

5                       3                           0

6                       2                           0

2                       2                           1

 

But it should be like that:

DataValue        RandomValue       Counter Value

4                       4                           1

5                       3                           0

6                       2                           0

2                       2                           2 (will remember the previous value and then increment)

 

If it was normal C# language, it would be easy. For example:

int counter; //it is my global value

for(int i = 0; i < dataValue.size; i++)

{  

   if(dataValue == randomValue)

   {

     counter++;

   }else{

    //do nothing 

}

 

Thanks for your time...

0 Kudos
Message 8 of 14
(6,411 Views)

Your shown C# code would still show the current value of the counter and not the "0" values like in your table.

What does your "False"-Case look like?

0 Kudos
Message 9 of 14
(6,404 Views)

@aybarskizilay wrote:

If it was normal C# language, it would be easy. For example:

int counter; //it is my global value

for(int i = 0; i < dataValue.size; i++)

{  

   if(dataValue == randomValue)

   {

     counter++;

   }else{

    //do nothing 

}


So you want something like this?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 10 of 14
(6,395 Views)