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

We are working to address an issue with subscription email notifications. In the meantime, be sure to check your favorite boards for new topics.

1-Newbie

## How to remove duplicates in a matrix column

Hello All,

Good Day!

I have been working on a program to sort the the data. I've a big input data table with 'n' number of columns. I've my results in column 'n' and needs to print this column as output. But the problem is, this column has some duplicate values (same number is repeating more than once). So, before printing this column as output I want to remove all the duplicate values in that column and print only unique values. Could anyone please let me know if there is any option in Mathcad prime like in excel to remove the duplicate values. Since I didn't find any option, I tried to write a loop with my little programming knowledge and is not really working. Could someone please help me to resolve this.

Regards,

As

8 REPLIES 8
23-Emerald III
(To:avarma)

This should do the job. It's a function that takes a (column) vect and deletes all duplicate values, so you have to supply it just the column you want to output.

Note that the result is sorted!

Success!
Luc

19-Tanzanite
(To:avarma)

Are the duplicate values always next to each other?

Do you need to delete the entire row of the table, or just the entries in one column?

Do you need to preserve the row order in the table?

23-Emerald III
(To:avarma)

And here's one that does not sort:

Success!
Luc

24-Ruby V
(To:LucMeekes)

Careful when using "match" for that purpose. The outcome may be undesired if the values in the vectors are rather small. The results depends on the value of TOL which by default is 10^-3.

Here is a routine which should not suffer from this problem:

Using your routine you would have to set TOL to 10^-6 or lower to get the same result.

23-Emerald III
(To:Werner_E)

Thanks, Werner. You're right.

I wrote the second mainly because it's more flexible, not knowing what the OP's data is:

Luc

24-Ruby V
(To:LucMeekes)

Yes, your second routine is more flexible and as we don't know if disturbing the order of the values is allowed sure the better option.

I quite often ran into that trap with "match" or "lookup" and its a pity that even with the convenient modifiers of the newer "Match" we still don't got a "real" equal.

Also its surprising that even with the data analysis extensions there is no utility function "removeDuplicates" provided out of the box.

24-Ruby IV
(To:LucMeekes)

Remove duplicates (())

24-Ruby V
(To:ValeryOchkov)

Still the duplicates are not removed and the benefit of using Mathcads Prefix notation seems not to help. Furthermore Ashok has not answered Richards questions yet, so we don't know, if changing the order of the values is allowed.

Using the infix notation we could write my local function "isIn" to look like the "not-element.of" symbol,

but Ashok wrote that he is using Prime and so he cannot make use of those notations as they unfortunately  are not available in Prime.

Announcements
Top Tags