LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simple 'if' statement

Hi,
Can anyone help me implement this simple 'if' condition:

if(i == A/2)
flag = 1;
elseif(i == A + B)
flag = 0;

I am not sure how to keep the flag high until next condition.

A and B are two consecutive integers. The flag becomes high at half of A and then remains high until 'i' reaches 'A+B'. This statement is in 'for' loop.

Thanks
0 Kudos
Message 1 of 8
(2,676 Views)
Hello,

Try this:

Hope it helps.
0 Kudos
Message 2 of 8
(2,669 Views)
Hello Paulo,
Opening error... my version is 7.0 whereas yours is 7.1.1. Any suggestions?
0 Kudos
Message 3 of 8
(2,664 Views)
Paulo... can you send it as an image file of block diagram(jpg)... that would be easier.

Thanks
0 Kudos
Message 4 of 8
(2,663 Views)
Hi,

Try it now. It's saved in 7.0.
With a jpg is difficult, because it as case structures.
0 Kudos
Message 5 of 8
(2,657 Views)
Jeguna,

Your problem seems to be a bit undefined because you don't define the output for the default case (if both don't match!). If I assume that the output is only "1" if i==A/2 and "0" in all other cases (and the second comparison is thus irrelevant), you could use something like the simple code shown in the attached image.


(Of course it is always dangerous to directly compare DBL because of possible precision errors. You might need to e.g. check if the difference is below a certain threshold.)
0 Kudos
Message 6 of 8
(2,652 Views)
Hi Jeguna. Your code and your textual description are condradicting. To execute the code you should use Altenbach's code and to execute the description you should use Paulo's.
An improvement to Paulo's code would be to use the In range VI from the comparison pallete - and use the In range output as your flag - as long as i is between the two numbers it will be T. This would rid you of the big case structure.

___________________
Try to take over the world!
0 Kudos
Message 7 of 8
(2,636 Views)
Alten,
Thanks for the reply. My default case would be 'flag=0'.

To make it more clear, A and B stand for two counters, which run consecutively... A B A B and so on.... when my reference counter 'i' reaches 'A/2', it sets flat to '1' until it reaches 'A + B'. Thus, the 'flag' would become high at A/2 and remain until A + B. Then becomes '0'.

Hope that clarifies
0 Kudos
Message 8 of 8
(2,634 Views)