cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

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

abirlea
4-Participant

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

10 REPLIES 10

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.

abirlea
4-Participant
(To:Werner_E)

Quick and easy solution to my problem. Thank you!

LucMeekes
23-Emerald III
(To:abirlea)

Here's another implementation:

LM_20180327_RemoveDuplicates.png

Success!
Luc

Clever way, like it!

It inspired me to the following variant:

Bild1.png

Its so much smaller in real Mathcad:

Bild2.png

LucMeekes
23-Emerald III
(To:Werner_E)

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

Thanks for pointing that out, Luc!

You are perfectly right. As the "last" function already takes care of the ORIGIN, the "O+" part must be omitted (the same applies for the Prime version, of course.

Bild1.png

Guess I confused it with this variant where "rows" is used instead of the "last" function:

Bild2.png

Tomek1
5-Regular Member
(To:Werner_E)

Hi,

I tried your program but for some reason doesn't work. Please refer to attached. 

 

Regards, 

T.

Tomek1
5-Regular Member
(To:Werner_E)

with correct file attached. 

Werner_E
24-Ruby V
(To:Tomek1)

The reason for the error you get is the equal sign ater the function definition.

Furthermore you have grabbed an erroneous version of the function. Its described in Lucs and my posts above. You have to delete the O+ as indicated  - otherwise it would only work OK if ORIGIN=0.

B.png

Tomek1
5-Regular Member
(To:Werner_E)

Thanks Again!

Top Tags