From: ravi gtg on
Hi guys, i'd like ur help.

If I have a matrix A as follows:

A = [ 0 2 2;
2 2 2;
0 0 4;
4 0 0]

I would like to output that there are actually 5 two's and 2 four's.

So , for example in a vector, the result would be:

vector = [ 5 2 ]


thanks
ravi
From: us on
On Jul 27, 10:07 pm, "ravi gtg" <ravi_...(a)hotmail.com> wrote:
> Hi guys, i'd like ur help.
>
> If I have a matrix A as follows:
>
> A =  [ 0   2     2;
>          2   2     2;
>          0   0     4;
>          4   0     0]
>
> I would like to output that there are actually 5 two's and 2 four's.
>
> So , for example in a vector, the result would be:
>
> vector = [ 5   2 ]
>
> thanks
>  ravi

one of the many solutions

m=[
0 2 2
2 2 2
0 0 4
4 0 0
];
r=histc(m(:),unique(m(m~=0))).'
% r = 5 2

us
From: Oleg Komarov on
"ravi gtg" <ravi_071(a)hotmail.com> wrote in message <i2ne9r$mne$1(a)fred.mathworks.com>...
> Hi guys, i'd like ur help.
>
> If I have a matrix A as follows:
>
> A = [ 0 2 2;
> 2 2 2;
> 0 0 4;
> 4 0 0]
>
> I would like to output that there are actually 5 two's and 2 four's.
>
> So , for example in a vector, the result would be:
>
> vector = [ 5 2 ]
>
>
> thanks
> ravi

unA = unique(A);
[histc(A(:), unA) unA]
5 0
5 2
2 4

Oleg