Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: How to use "Unique"
Posted:
Nov 12, 2012 12:42 PM
|
|
In article <k7rai0$n1i$1@newscl01ah.mathworks.com>, "Kevin Ellis" <kevin.ellis86@gmail.com> wrote:
> Hello, > > I am having trouble figuring out how to use "unique" to find the index of > identical elements in a single column cell array. As an example, I have a > cell array with the following data: > > A = > ''231234242800100043062.68' > ''231234242800200043208.86' > ''231234242800400042964.91' > ''231234242800500038861.19' > ''231234242800600010255.99' > ''231234242800900054183.5' > ''231234242801100077938.9' > ''231234242801200049682.26' > ''23123424800900054183.5' > ''23123424800900054183.5' > ''23123424GHA0200020256.36' > > I have been trying to use unique to find the index of identical elements. In > this case, the third and second to last values are equal to one another. I > need to figure out a way to output the indices 9 & 10. I have tried using > [C1, ia1, ib1] = unique(A,'first'), but still do not understand how "ib1" can > be used to find the indices 9 & 10. > > Also, the order is crucial. The order shown in the example cell array cannot > change. I realize this may be a question for the help file, but after looking > at it I still do not fully understand so I am hoping someone could help. > Thanks. > > Kevin
Try this:
[~,~,ib1] = unique(A); j = find(histc(ib1,1:max(ib1)) > 1); dupes = find(ismember(ib1,j));
It will find ALL indices of items in A that are duplicated, even if there is more than one such unique item, i.e., if
A = {'a','a','b','c','c'}
then dupes will be [1 2 4 5];
-- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
|
|
|
|