%% Find Duplicate Array Elements
% Determine which elements in a vector appear more than once.
%
% Create a column vector with values between 1 and 5.

v = [1 1 2 2 3 5 3 3 1 4]';

%
% Use groupcounts to determine the unique groups in the vector and count the group members.

[gc,grps] = groupcounts(v)

% Determine which elements in the vector appear more than once by creating a logical index for the groups with a count larger than 1. Index into the groups to return the vector elements that are duplicated.

duplicates = grps(gc > 1)

% Copyright 2020 The MathWorks, Inc.