Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- How to remove duplicate entries in an array using ...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

03-27-2018
12:27 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-27-2018
12:27 PM

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.

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

03-27-2018
12:51 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-27-2018
12:51 PM

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 10

03-27-2018
12:51 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-27-2018
12:51 PM

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.

03-28-2018
04:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-28-2018
04:00 AM

Quick and easy solution to my problem. Thank you!

03-27-2018
05:17 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-27-2018
05:17 PM

Here's another implementation:

Success!

Luc

03-27-2018
05:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-27-2018
05:43 PM

Clever way, like it!

It inspired me to the following variant:

Its so much smaller in real Mathcad:

03-28-2018
06:23 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-28-2018
06:23 AM

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.

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

Luc

03-28-2018
07:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

03-28-2018
07:07 AM

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.

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

07-03-2018
01:57 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-03-2018
01:57 PM

Hi,

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

Regards,

T.

07-03-2018
01:58 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-03-2018
02:59 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-03-2018
02:59 PM

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.

07-04-2018
04:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-04-2018
04:20 AM

Thanks Again!