command unique without sorting??
327 views (last 30 days)
i need to delete the double numbers in a vector and create a new vector without the doubles and maintaining the same order... i used unique but i dont know how to let them stay in the same order! for exemple for
v=[7 6 3 3 2 3 5 2 2 4 1 4]
it should be
v=[7 6 3 2 5 4 1]
Honglei Chen on 26 Mar 2014
You changed your question from yesterday, please don't do so. As to your new question, my answer above already covered it.
Honglei Chen on 25 Mar 2014
[vu,~,idx] = unique(v.','stable')
vs = accumarray(idx,ones(numel(v),1))
Gabor on 1 May 2021
Edited: Gabor on 1 May 2021
In my opinion unique should be "stable" by default. If someone wants to sort, than there is sort commant that for. What does sorting by default in unique has to do with removing duplicate values? In same logic why doesnt sorting has default unique function built in? Or do I missing any point? For me it does not make any sense nor being logical.