MATLAB: Finding non-unique values in an array.

arraysmatrix manipulationnon-uniquerowsunique

I have an array that I would like to extract the non-uniques rows from…
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [1] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [3] [25]
So I would like to find the rows that have non-uniques values in the fifth (last) column so I get…
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [1] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [0]
Thanks in advance!

Best Answer

C = {'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [1] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [3] [25]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [0]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [4]
'\\campus\home\home2014...' 's-pl T2* FGRE' [1] [2] [4]
};
% Unique values
[~,idxu,idxc] = unique(cell2mat(C(:,5)));
% count unique values (use histc in <=R2014b)
[count, ~, idxcount] = histcounts(idxc,numel(idxu));
% Where is greater than one occurence
idxkeep = count(idxcount)>1;
% Extract from C
C(idxkeep,:)
Related Question