finding duplicates

333 次查看(过去 30 天)
Danielle Leblanc
Danielle Leblanc 2011-8-5
A=[ 1 1 2 2 3 3 3];
unique(A)=[1 2 3]; but I want to find the duplicates that are not the first occurrence. i.e x=[2 4 6 7]; I typed help unique but I couldn't figure out if I and J reported by this function helps with my purpose.I know that I can program it but i want to be as efficient as possible in my codes to reduce the running time.

采纳的回答

the cyclist
the cyclist 2011-8-5
Here is one way:
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))

更多回答(1 个)

Jan
Jan 2011-8-5
Another solution:
A = [1 1 2 2 3 3 3];
[U, I] = unique(A, 'first');
x = 1:length(A);
x(I) = [];
  2 个评论
Oleg Komarov
Oleg Komarov 2011-8-5
Clever and simple.
Jan
Jan 2011-8-5
I'm inspired by Marsaglia's KISS random number generator: "Keep It Simple Stupid".

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by