From: Darlis on
Dear all

Do you know the matlab builtin function to get a count for each group
for example :
data = [
2;
4;
1;
2;
1;
3;
1;
2;
2;
1;
5;
4;]

the result I hope to obtain :
1 4
2 4
3 1
4 2
5 1

Thank you very much;

Dalris
From: Darlis on
I have tried to use the classic (iterative) way.
I look for the fastest way, maybe there is a matlab builtin function

for i=1:max(data)
grp(i,1)=i;
grp(i,2)=size(find(data==i),1);
end;

Regards
Darlis

"Darlis " <darlis(a)cs.its.ac.id> wrote in message <hip03e$57v$1(a)fred.mathworks.com>...
> Dear all
>
> Do you know the matlab builtin function to get a count for each group
> for example :
> data = [
> 2;
> 4;
> 1;
> 2;
> 1;
> 3;
> 1;
> 2;
> 2;
> 1;
> 5;
> 4;]
>
> the result I hope to obtain :
> 1 4
> 2 4
> 3 1
> 4 2
> 5 1
>
> Thank you very much;
>
> Dalris
From: Pekka Kumpulainen on
"Darlis " <darlis(a)cs.its.ac.id> wrote in message <hip03e$57v$1(a)fred.mathworks.com>...
> Dear all
>
> Do you know the matlab builtin function to get a count for each group
> for example :
> data = [
> 2;
> 4;
> 1;
> 2;
> 1;
> 3;
> 1;
> 2;
> 2;
> 1;
> 5;
> 4;]
>
> the result I hope to obtain :
> 1 4
> 2 4
> 3 1
> 4 2
> 5 1
>
> Thank you very much;
>
> Dalris

One opition is to use howmany from FEX:
http://www.mathworks.com/matlabcentral/fileexchange/?term=howmany

[a,b] = howmany(data)
>> [a b]

ans =

1 4
2 4
3 1
4 2
5 1
From: us on
"Darlis " <darlis(a)cs.its.ac.id> wrote in message <hip03e$57v$1(a)fred.mathworks.com>...
> Dear all
>
> Do you know the matlab builtin function to get a count for each group
> for example :
> data = [
> 2;
> 4;
> 1;
> 2;
> 1;
> 3;
> 1;
> 2;
> 2;
> 1;
> 5;
> 4;]
>
> the result I hope to obtain :
> 1 4
> 2 4
> 3 1
> 4 2
> 5 1
>
> Thank you very much;
>
> Dalris

one of the many solutions

[du,dx,dx]=unique(data);
dx=accumarray(dx,1);
r=[du,dx]
%{
% r =
1 4
2 4
3 1
4 2
5 1
%}

us
From: ImageAnalyst on
Another alternative is to use the hist, histc, or imhist function.