From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1D array elements unique element

Solved!
Go to solution

Hello everyone,

 

I have an 1D array containing a lot of elements. It looks like that [Mesure1,Mesure1,Mesure1,Mesure1,Mesure2,Mesure2,Mesure2,Mesure3,Mesure3...]. I just want to create an array which looks like that [Mesure1,Mesure2,Mesure3], I don't want two same elements in my array because they will be the names of the groups of the tree I am creating.

 

Would you find an elegant way to do it?

 

Thank you !

0 Kudos
Message 1 of 5
(6,049 Views)

Use for loop with auto indexing and Search 1D array + Insert into array.

Initialize SR with 1D string array.

Save in shift register and compare with previous elements.

insert into SR only if current element is not matching with previous array.

 

 

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
 
Amit Amrutkar @@
0 Kudos
Message 2 of 5
(6,048 Views)

Hi Lucas,

 

You can also use a variant's attributes to filter your array for unique elements. The Get Variant Attribute without input name will return an array with all the attribute names.

Unique Elements from Array.png

 

Best regards,

---
SergioR
Message 3 of 5
(6,023 Views)

I also would have suggested variant attributes, a key tool every LabVIEW programmer should know. (... at least until you hear my 2019 NI Week talk in May :D)

 


@Amit_Amrutkar88 wrote:

Use for loop with auto indexing and Search 1D array + Insert into array.

Initialize SR with 1D string array.

Save in shift register and compare with previous elements.

insert into SR only if current element is not matching with previous array.


LabVIEW programmers are visual, so instead of complicated words, I would recommend to just attach a VI or show a picture. Also avoid ambiguous acronyms (such as "SR" which can mean many things!). I am sure a beginner will not be able to solve anything according to your instructions. Also, "built array" would be more natural than "insert into array".

 

Your "solution" does not scale well for large arrays, because the comparison needs to be done with more and more elements, so the problem grows with N² of the size and becomes very slow for very large arrays. Variant attributes scale with log2N of the size and are thus much more efficient. (If you don't want to use variant attributes, sorting the array first would scale with NlogN for a better compromise).

 

 

0 Kudos
Message 4 of 5
(5,998 Views)
Solution
Accepted by topic author LucasDev

rd.png

or, if you need order preserved, use the attached vim.

 

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 5
(5,981 Views)