From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## optimize case structures for a same calculation

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.

Message 1 of 5
(2,305 Views)
Solution
Accepted by topic author acewong7

## Re: optimize case structures for a same calculation

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?

Message 2 of 5
(2,295 Views)

See attached.

Message 3 of 5
(2,294 Views)

Message 4 of 5
(2,292 Views)

## Re: optimize case structures for a same calculation

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.

Message 5 of 5
(2,274 Views)