"Lin " <shenqlv@yahoo.com> wrote in message <gqai9h$66b$1@fred.mathworks.com>...
> Hi all.
>
> Say I have something as shown:
>
> x' =
> 2
> 3
> 4
> 5
> 2
> 6
> 7
> 3
> 4
>
> How can i find the number of match data? I try to do some elaboration. i take the first value '2' and compare against the rest of the data to find a match. If yes, counter + 1. Then i take the next value '3' and do the comparison again.
>
> Expected result:
>
> THere are 3 sets of match data, 2, 3 and 4.
>
> I could not achieve the results using the unique function, because it reduces to something like
> 2
> 3
> 4
> 5
> 6
> 7
>
> I tried using ismember too, but the code is not so dynamic, since i need to makes several changes when i change the input data.
>
> Is there any way where i can achieve my expected results? Thanks for helping.
The general approach involves both UNIQUE and HISTC
histc(X,unique(X))
For positive integers, one could use the sparse trick:
x = [2 3 4 3 5 100 2 3 4 3 4] ;
[Val,N,N] = find(sparse(x,1,1)) ; % 2nd output unused
disp([Val N]
hth
Jos
