LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

case structure for comparing values

Thanks for offering the sample with the In Range and Coerce functions to create the Boolean array.  But, why is the third case "4" and not "3". 

 

I am reading the Labview help about "Boolean Array to Number Function" and it says....,

 

"For example, if you wire an array of two Boolean values to this function and neither value is TRUE, the function returns a value of 0. If the first Boolean value is TRUE, the function returns 1. If the second Boolean value is TRUE, the function returns 2. If both Boolean values are TRUE, the function returns 3."

 

So, how does the third case in your illustration become 4?  If case array values 1 and 2 are both FALSE and the third one is TRUE, I would have guessed the output value to be 3, not 4.  For example, if you entered a value of 25, that should make 1 and 2 both FALSE and 3 TRUE.  For my own learning tool, I added string indicator to follow the functional output of the 4 cases including default.

0 Kudos
Message 11 of 20
(1,465 Views)

I would not recommend this approach. The formula node should be reversed for just that, formulas. It is not intended to be used a C emulator by allowing you to write significant parts of your code in a text format. By doing so you will lose many of the optimization sand benefits of the native LabVIEW language.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 12 of 20
(1,464 Views)

Hi Mark,

I am sorry, but, I am not clear about which part of the approach you would not recommend?  What "formula node" are you talking about?  What do you think would be a better architecture that provides better optimization?  I am very much interested in speed, so, I am interested in making sure that my code is efficient.

0 Kudos
Message 13 of 20
(1,463 Views)

@JFT' wrote:
Hi Bernie,
You can do that and many others things, using only one structure. I'm talking above "Formula node". See the help of this structure directly in LV, and you will find a very useful aid.

JFT

Sorry, I was referring to what this person had recommended. He was suggesting using the formula node to implment you decision processing.

 

However on second thouht if all that you used the formula node to do was output a value based on testing the ranges of the input this would be fine. If however you tried to implement complex code (other than actual calculations) I would not recommend that.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 14 of 20
(1,456 Views)

Thanks, Mark, but, what does "formula node" mean?  I am very new to Labview and learning a lot of things, but, I can't say that I could define "formula node" if asked.  Would you kindly offer a definition of description of what that phrase means?

Thanks,

Dave

0 Kudos
Message 15 of 20
(1,447 Views)

A formula node is a structure within LabVIEW that allows you to enter formulas and some basic programming constructs in txt form with a syntax that is similar to C. The formula node has inputs and outputs so that data can be passed in and out of it similar to the way a subVI works. LabVIEW is a great language but it is not very easy to implement complex mathematical equations in the native language. This is one area where the tradition text representation of an algorithm is easier to understand. Formula nodes are very good in those instances. However if someone is making the transition from text based programming to LabVIEW they may be tempted to overuse the formula node where native LabVIEW constructs would probably be better suited.

 

Here is a basic example of a formula node.

 

Formula Node.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 16 of 20
(1,441 Views)

Thank you very much.  I understand it now.  I believe that formula nodes are possible only with the Math Scripts add-on.  Is that your understanding too?  I recall reading about formula nodes, but, I couldn't practice any exercises with them because I don't have the Math Scripts add-on.

0 Kudos
Message 17 of 20
(1,437 Views)

The formula node is included in all releases. You can find it under the Structures palate. I don't have any of the Mathscript addons either.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 18 of 20
(1,433 Views)

@dav2010 wrote:

Thanks for offering the sample with the In Range and Coerce functions to create the Boolean array.  But, why is the third case "4" and not "3". 

 

I am reading the Labview help about "Boolean Array to Number Function" and it says....,

 

"For example, if you wire an array of two Boolean values to this function and neither value is TRUE, the function returns a value of 0. If the first Boolean value is TRUE, the function returns 1. If the second Boolean value is TRUE, the function returns 2. If both Boolean values are TRUE, the function returns 3."

 

So, how does the third case in your illustration become 4?  If case array values 1 and 2 are both FALSE and the third one is TRUE, I would have guessed the output value to be 3, not 4.  For example, if you entered a value of 25, that should make 1 and 2 both FALSE and 3 TRUE.  For my own learning tool, I added string indicator to follow the functional output of the 4 cases including default.


The output to boolean array to number is three if the first AND second case are both true.  Binary 00000011 is 3 decimal.

 

Each digit is the result of a true/false comparison (the in range/coerce function).  So if your 3rd condition is true, then the 3rd digit is a 1 (the 1st and 2nd are zero or should be because your comparisons should never overlap.)  So you have 00000100 in binary which is 4 in decimal.  This is all binary logic/conversion.

 

Another alternative is to searcha 1D array on the boolean array looking for a True.  Then you will get a 0 for the initial condtion, 1 for the second condtion, 2 for the 3rd, and so on.  If nothing is true, then you should get a -1.  This method should work just fine for you also since your conditions should only have 1 true.  If you had multiple Trues, it will only give you the element # of the first True.

Message 19 of 20
(1,427 Views)

ALL RIGHT!! Thanks, that is a wonderful explanation. I really appreciate that.  I would not have gleaned that from the Labview Help alone.

Dave

0 Kudos
Message 20 of 20
(1,423 Views)