How to use Uniquetol without sorting?

Hello everyone,
I'm using the function "Uniquetol" to remove the duplicate vector from a matrix A which the size is (3, 10).
B = ( uniquetol(A', 1e-6, 'ByRows', 1) )';
It works very well, but it is also sorting my matrix which what I don't want
Please, can anyone tell how can we use the function "Uniquetol" without sorting ?

 Accepted Answer

[~, colindices] = uniquetol(A', 1e-6, 'ByRows', true); %get indices of unique value. Is sorted BY VALUE
B = A(:, sort(colindices)) %Use the indices sorted BY INDEX instead

4 Comments

AMEHRI WALID
AMEHRI WALID on 12 Jul 2019
Edited: AMEHRI WALID on 12 Jul 2019
Great, it's working like a charm !
Thank you :)
I encountered the same problem and I tried your solution but it didn't work for me. For example, let
A=[0.71 -0.71 -0.69 0.69]
Then I tried
[~, idx] = uniquetol(A,0.1);
A(sort(idx))
But it returned [-0.71 0.69] instead of [0.71 -0.71].
Both solutions are equally valid. They respect the order in the original matrix.
Sorry Huy, there is not reason your solution is right and other is wrong.
Try this:
A = [0.05 0.11 0.18; ...
0.46 0.52 0.76;...
0.34 0.36 0.41; ...
0.18 0.21 0.29; ...
0.46 0.52 0.76;...
0.05 0.11 0.18;];
%
[~, colindices] = uniquetol(A, 'ByRows', true)
sort(colindices)
% get indices of unique value. Is sorted BY VALUE
B = A(sort(colindices),:)

Sign in to comment.

More Answers (0)

Tags

Asked:

on 12 Jul 2019

Commented:

on 23 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!