01-09-2021 01:16 PM
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
Solved! Go to Solution.
01-09-2021 01:53 PM
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
01-09-2021 05:31 PM - edited 01-09-2021 05:38 PM
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)
01-09-2021 05:36 PM
01-09-2021 09:22 PM
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.
01-11-2021 03:35 AM - edited 01-11-2021 03:36 AM
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.
01-11-2021 10:36 AM - edited 01-11-2021 10:37 AM
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).
01-11-2021 10:48 AM
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.
01-11-2021 11:07 AM
Thanks, wiebe@CARYA,
The array size is about 170,000. Unfortunately, I don't want to upgrade from LabVIEW 2018 SP1 to LabVIEW 2020.
01-11-2021 03:47 PM
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.
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.