Find unique values of a vector with same order as in the vector in matlab

后端 未结 3 1500
执笔经年
执笔经年 2021-01-19 14:03

I have a vector A=[2,5,6,2,4,13,34,3,34]. I want to find a unique value of this vector but not in sorted order! I searched in Matlab site and I found this function

3条回答
  •  庸人自扰
    2021-01-19 14:13

    A=[2,5,6,2,4,13,34,3,34];
    [B, ia] = sort(A);     % B = A(ia)
    ib(ia) = 1:length(B);  % A = B(ib)
    [C, ic] = unique(B);   % C = B(ic)
    D = B(ib(ic));         % unsorted unique values
    

提交回复
热议问题