MATLAB: How to get vectors of common duplicates in a cell array

duplicatesMATLABunique

Let's say I have a cell array of values, some of which are duplicates:
A = {'a', 'b', 'c', 'c', 'a', 'a'}
How can I get an output of the duplicate index values, grouped together? Should look something like this:
duplicates = {[1,5,6], [3,4]}
Thanks!

Best Answer

>> [~,~,X] = unique(A);
>> [B,Y] = hist(X,1:max(X));
>> C = arrayfun(@(y)find(X==y),Y(B>1),'uni',0);
>> C{:}
ans =
1 5 6
ans =
3 4
Or
>> [~,~,X] = unique(A);
>> V = 1:numel(A);
>> C = accumarray(X(:),V(:),[],@(v){v});
>> C(cellfun(@isscalar,C)) = [];
>> C{:}
ans =
1
5
6
ans =
3
4
Or a simple loop.