Labview : 1D array sorting after removing minus numbers and duplicates

2.1k Views Asked by At

I have one number array like below picture.

enter image description here

I'd like to remove whole minus numbers and duplicate numbers, and sort the array in ascending order, like below.

enter image description here

How could I do that?

3

There are 3 best solutions below

0
On BEST ANSWER

This does the job :

  • Sort the array
  • Find 0 and cut the array
  • Substract rotated array to find doubles (=0)
  • remove doubles

Block Diagram

Front Panel

0
On

Unless there was a real efficiency need, I'd shoot for simplicity and readability:

  1. Sort the array
  2. Feed it into a for loop with a conditional concatenation terminal
    1. Use a feedback node to get the last value
    2. If this value is >0 and != to the last value, send true to the concatenation terminal.

You could always AND the >0 and != tests together and wire that directly to the concatenation terminal.

The output array from the for loop will be what you're looking for.

0
On

I like Vivien's use of Threshold 1D Array and Array Subset to remove the negative values, but the rotate and subtract before removing zeroes seems unnecessarily complex. Here's a solution with a For loop, shift register and conditional indexing:

LabVIEW 2014 VI snippet (drag and drop on the VI block diagram)

Note that we have to initialise the shift register with something, or it would remember data from the previous run, giving unwanted behaviour (the same would be true of a feedback node) - so we make sure that the first array element will always be included by ensuring that the initialisation value is not equal to the first element.