LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sorting out 1D array of strings

Solved!
Go to solution

Hello NI community,

 

Attached is my LabVIEW 2018 SP1 application that sorts out an array of unique strings from an array of arbitrary strings. I would appreciate your help in getting the following answer in order:

 

PFC124

TR0012

A00123

A00001

202MAR

 

0 Kudos
Message 1 of 16
(2,018 Views)

You have an Array of (something).  You want to (put a verb here -- hint, look at the first four letters of your Post's title).  See if there is a function in one of the Palettes in the Block Diagram that suggests a function that will do some of the work for you.

 

If you want to learn LabVIEW, you will have to do a little bit of work (and thinking) for yourself.

 

Bob Schor

 

 

0 Kudos
Message 2 of 16
(2,005 Views)

It looks more like you want to remove duplicates and keep entries in existing order. It also seems like all duplicate entries are adjacent.  Nothing to do with "sorting"!

 

Can you please fully specify the requirement and assumptions. (e.g. does it need to continue to work even if duplicated are not adjacent?)

 

(Looking at your code, I recommend a few tutorials first. Your shift register needs to be initialized with an empty array, but if you would use an autoindexing output tunnel you could eliminate the case structure and shift register for the array. You might still need a shift register to keep the previous entry for comparison)

0 Kudos
Message 3 of 16
(1,976 Views)
Solution
Accepted by topic author cha@bellflight.com

See if this can give you some ideas.

 

altenbach_0-1610235376342.png

 

Message 4 of 16
(1,972 Views)
 

Thanks to your more efficient & elegant solution than mine (see below), altenbach. I will try to remember using "autoindexing output tunnel".

 

Also, my 1D array of strings does not contain duplicates that are NOT adjacent.

 

2021_01_09_sort_1D_string_answer_02.jpg

 

0 Kudos
Message 5 of 16
(1,956 Views)

remove duplicates.png

Look inside for the most optimal general solution. Your current solution might actually be faster, but is less general. I wouldn't worry about that, unless the array is milieus of elements, or if you call it millions of times.

 

One thing to consider is to avoid the duplicates it the first place. When adding, check if it changed and don't add it if it didn't.

0 Kudos
Message 6 of 16
(1,907 Views)

wiebe@CARYA wrote:

 

Look inside for the most optimal general solution.


From their post, they are using LabVIEW 2018. (Maps and Sets are only in available 2019+ and that's why I did not mention it).

 

(Of course the set based solution is much more general because it does not assume that the elements are already grouped and it still returns the output in the order of first occurrence).

0 Kudos
Message 7 of 16
(1,884 Views)

Thanks for mentioning wiebe@CARYA's LabVIEW 2020 approach, altenbach,

 

I have many LabVIEW 2018 SP1 NI PXIe hardware applications. I don't think I want LabVIEW 2020 upgrade.

0 Kudos
Message 8 of 16
(1,876 Views)

Thanks, wiebe@CARYA,

 

The array size is about 170,000. Unfortunately, I don't want to upgrade from LabVIEW 2018 SP1 to LabVIEW 2020. 

0 Kudos
Message 9 of 16
(1,870 Views)

OpenG's "Remove Duplicates from 1D Array" removes duplicates whether they are adjacent or not, and also it's polymorphic so it'll work for string arrays, integer arrays, and so on. No need to reinvent the wheel.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 10 of 16
(1,851 Views)