matlab unique 顺序不变

对于一个向量,使用unique去重后会自动排序,为了保持原顺序:

A = [5,1,8,5,2,8,3,9,6,1];
[i,j] = unique(A,'first');
B = A(sort(j));

----------------------------------------

B = [5,1,8,2,3,9,6]

posted @ 2014-01-08 17:08  ChasingSunrise  阅读(1367)  评论(0编辑  收藏  举报