You can use the second output argument unique, which returns the index of unique elements. To display them in their original order, use the function sortin the index vector before indexing the original vector.
x = {'rrr' 'aaa' 'bbb' 'hhh' 'aaa' 'ppp'};
[y,i] = unique(x);
x(sort(i))
Output:
ans =
'rrr' 'bbb' 'hhh' 'aaa' 'ppp'
source
share