Skip to main content
March 27, 2018
Solved

How to remove duplicate entries in an array using a program.

Hi,

 

I'm trying to create a program that removes duplicate entries from an array (vector) in Mathcad.

I have managed to write a program that converts all the duplicates into "null", but is there a way to get rid of the elements completely and get the "Result" array?

 
Thank you.

Werner_E
Werner_EAnswer
25-Diamond I
March 27, 2018

Always better to post the worksheet as well as we don't like retyping things.

change "null" to NaN and use filterNaN(array) at the end of your program (instead of just array).

As an alternative after replacing duplicates with "null" you could use  trim(array, match("null",array)) at the end.

10 replies

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
March 27, 2018

Always better to post the worksheet as well as we don't like retyping things.

change "null" to NaN and use filterNaN(array) at the end of your program (instead of just array).

As an alternative after replacing duplicates with "null" you could use  trim(array, match("null",array)) at the end.

Translate
March 28, 2018

Quick and easy solution to my problem. Thank you!

Translate
23-Emerald IV
March 27, 2018

Here's another implementation:

LM_20180327_RemoveDuplicates.png

Success!
Luc

Translate
Werner_E
25-Diamond I
March 27, 2018

Clever way, like it!

It inspired me to the following variant:

Bild1.png

Its so much smaller in real Mathcad:

Bild2.png

Translate
23-Emerald IV
March 28, 2018

Werner

I'm not sure your implementation works for ORIGIN=1.

You have an O+ in the index of R when assigning a new member, together with using last(R); that adds another (empty, or 0=zero) with every addition of a member.

LM_20180328_RemoveDuplicates.png

OK.... I'm sure it does NOT work as intended for any value of ORIGIN other than 0.

 

Luc

Translate