Skip to main content
1-Visitor
January 14, 2017
Question

How to remove duplicates in a matrix column

  • January 14, 2017
  • 3 replies
  • 5450 views

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.

Thanks in advance!

Regards,

As

3 replies

23-Emerald IV
January 16, 2017

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
January 16, 2017

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 IV
January 16, 2017

And here's one that does not sort:

Success!
Luc

25-Diamond I
January 16, 2017

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 IV
January 16, 2017

Thanks, Werner. You're right.

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

Luc