Find unique values of a vector with same order as in the vector in matlab
matlab, unique, vector
Solution
Assuming you have a vector (so the `'rows'` version makes no sense), here's a solution based on `bsxfun`:
[~, ind] = max(bsxfun(@eq, A, A.'));
ind = ind(ind>=1:numel(ind));
C = A(ind);
How it works: Do all pairwise comparisons between elements (`bsxfun(@eq, A, A.')`). For each element, find the index of the first equal element (`[~, ind]=max(...)`). If that index is smaller than the current position (that is, if there's a previous element which is equal to the current one), disregard it (`ind = ind(ind>=...`). Use the surviving indices to generate the result (`C = A(ind)`).
Problem
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 ``` [C, ia, ic] = unique(A,'rows','stable') ``` but this function is not recognized in Matlab R2011a ! probably this function works on version higher than 2011 !! anybody knows how can I find the unique values of A with the same order as in A like : A=[2,5,6,4,13,34,3]