Showing results for 
Search instead for 
Did you mean: 

optimize case structures for a same calculation

Go to solution

Hi, all. I want to compare an array of numbers with 0 first, if they are bigger than zero, we do a simple calulation such as 10+10; if they are smaller than 0, we do another simple calulation such as 10-5; of course it can be realized by the VI i wrote in the attachment, but I wonder if we have any better ways to solve it, maybe only one case structure since we have the exactly same calculation for the same situation. Thanks for any useful suggestions. I have updated a picture just in case if you don't want to download the VI. 

Download All
0 Kudos
Message 1 of 5
Accepted by topic author acewong7

You can search the 1-D boolean Array for a True value.  Then the value will be -1 (no trues), 0, 1, 2, or 3 for the index.  Hav that drive a single case structure. Where the respective indicator is in each case.


Of course if all the calculations are exactly the same (I assuming 10-5 is just simplified), you can put the calculation outside of the case structure and feed it to the respective cases.


EDIT:  You don't need to build an array of zeroes to compare to another array.  You can just use a scalar zero.  And you don't need that.  Just use the >0 primitive.


Actually, I'm not really sure what you are trying to do here.  Why do you have different indicators in the false cases and the true cases?

0 Kudos
Message 2 of 5
0 Kudos
Message 3 of 5

0 Kudos
Message 4 of 5

thanks for the fast reply, RavensFan! It is very straightfowd to compare two arrays because i have a lot of troubles with "you have connect two wires with different data type" issue, so now when I write the code, I want to always make them to be the same type. The indicator for individual case structure are different becasue I used a Index Array to get the Ture or False for each comparison. Thanks for your explaintion, and also with KAS's codes, i think I understand this completely. Thank you guys very much. 

0 Kudos
Message 5 of 5