MATLAB Answers

C Zeng

About unique command problem

Asked by C Zeng
on 3 Apr 2013


I used unique(A,'rows') to find unique rows of matrix A, however, it has a problem that after picking unique rows, it will order them in a manner. That is bad to my problem, I want to keep the order as originally in A.

Is there a command that prohibits sorting rows but only deleting same rows(reserve the first appearance) in MATLAB?





No products are associated with this question.

1 Answer

Answer by per isakson
on 3 Apr 2013
 Accepted answer

Doc says:

    [C,ia,ic] = unique(A,setOrder) and [C,ia,ic] = unique(A,'rows',setOrder) returns
    C in a specific order. setOrder='sorted' returns the values (or rows) of C in
    sorted order. setOrder='stable' returns the values (or rows) of C in the same 
    order as A.



  1 Comment

Oh, thanks per isakson, I should be familiar with doc myself. :-)

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!