Showing results for 
Search instead for 
Did you mean: 

How to compare element inside the array and the output need to split by its condition in array form


Im just newbie in labview and . I have a problem on how 

after i compare , i need the output to be like 2 condition 

output 1                                      output 2
#sets of number less than 3      #sets of no more than 3


hope anyone could help me . I try to find the related topics..but still cant get thow..

Appreciate any help



Download All
0 Kudos
Message 1 of 3

Spend more time with the LabVIEW Tutorials.  Be sure that you understand the Principle of Data Flow, which means that you can write your entire program without needing a single Frame structure (because everything is connected by wires and data travels in those wires).  Just for fun, right-click the Frame Sequence and choose "Remove Sequence" -- your code will run exactly as before (but will be neater, more compact, and easier, I think, to read).


It is not clear what type of output you desire.  What do you mean by "#sets of number less than 3"?  Is this the same as saying "A set of all numbers < 3"?  [I'm confused by "#sets"].  Note that a "Set of numbers < 3" and a "Set of numbers no more than 3" are almost the same except that the number "3" can be in the second set.


I see you are using LabVIEW 15.  Learn about the types of output tunnels for the For and While loop.  In particular, learn how the Conditional Indexing Tunnel makes creating arrays very simple (with no need for the Build Array function).


Do not use Local Variables -- they are a Trap for the Unwary.  In your code, you can simply put the Indicator where your Local Variable is now wired.


Bob Schor

0 Kudos
Message 2 of 3

You're fairly close to a working solution. As usual (Smiley Wink) I agree with Bob Schor that some additional reading from the LabVIEW tutorials and knowledgebase articles would help you with this problem.


The conditional terminals that Bob mentioned are key to the simplest solution to your problem.


Note that within your current loop, you're using "Greater Than" as a comparison (didn't you want "Less Than", and "Less Than or Equal To"?

You want two different sets of outputs, so carry out two comparisons. Note that in your case, since your input is a set of random DBL values multiplied by 10, the chance of the two sets being different is miniscule. Perhaps you wanted to place values 0..2.999999999 in one group, and 3 to 10 in another?

If that is the case, consider which comparisons you need, and then place them in the loop.


In summary,

  • Use Conditional outputs to only output the elements that meet some condition
  • You can "branch" your wire (within the loop) to make multiple comparisons
  • You don't need the Build Array node, Shift Registers, or Local Variables (as Bob Schor explained)
  • If you really want what you described (< 3, <= 3) then the sets will almost always be the same for random DBLs without some rounding
  • You want to output the value (not the index to the sorted array). So don't add the value of "i" to your output - add the value of the input!
  • If you want to split the array into two parts at some value, there are much simpler methods (especially with a sorted array), but using the same ideas described above, you could use just one comparison and a "Not" node to get the two conditions you will need.

GCentralI'm attending the GLA Summit!
0 Kudos
Message 3 of 3