If I have an array [1 2 3 4 3 5 6 7 8 7]
, I'd like to find the list of non-unique entries: [3 7]
. I fail to find a simple way to do it. Any idea?
Update: I'd like to have a universal solution, which would also work with cell array of strings.
If A has length n, you can find the indices in A of the first occurrence of each entry and remove them from A:
A = [1 2 3 4 3 5 6 7 8 7];
n=length(A);
[~,IA,~] = unique(A);
out = unique(A(setdiff((1:n),IA)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With