Example Code

Remove duplicate entries in string array using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

Removes duplicate strings in a 1 dimensional string array and returns the reduced array unsorted.

 

Description

I needed a way of removing duplicate entries from a list which retained the original sorting of the list. All the methods I found resulted in the original list being resorted alphanumerically. This VI is the method I used to achieve this. I offer it here as a way of saying thank you to all the contributors whose examples have been very helpful to me in the past. It only works on string arrays, and works by adding some extra characters to duplicate strings. This means that there are some limitations to its use which are discussed in the comments on the block diagram. It uses nested For loops, so would be slow on large arrays. To work with numeric arrays, you could convert the numeric values to strings, process the strings, and then convert back to numbers.

 

Steps to Implement or Execute Code

  1. Download the VI
  2. Wire a string array to the Array In terminal
  3. Run the VI and take the reduced array from the Array Out terminal.

Requirements

LabVIEW 2012 (or compatible)

 

Additional Images
Block Diagram

main.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Mads
Active Participant
Active Participant
on

Most of the "remove duplicates" you found here, like this one,  give out a sorted array yes, but that is because there is already a very good implementation of the unsorted version freely available, it is in the OpenG toolkit. The sorting is just a trick to make the function much faster, useful if you need more speed and can accept the sorting (you can also use the sorted versions as a stage in an unsorted one).

The OpenG implementation is faster (about 3x overall on my computer at least) than your code, and does not have the limitations caused by the way you mark duplicates. The source code is open, so you can see how they've been able to make it so efficient.

pretech
Member
Member
on

Hmm.. not sure how I missed that the OpenG one does not sort! In my reading around the topic I manged to conclude that it sorted the array like the other ones I found.

Thanks Mads for taking the trouble to point it out.

I've now downloaded the Open G one  (what a mission...for some reason my computer and VIPM are not very compatible.) Eventually got it working, and it does not sort the array, so that's good.

Looks like I've wasted a day's work. Good thing I've got a forgiving boss!

Deekshith7
Member
Member
on

How to generate a Random Number from 1 to 50 ?

 

How to generate a Random Number from 1 to 50 without repeating in an  output array