Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
hist

Subject: hist

From: SM

Date: 26 Oct, 2009 19:28:02

Message: 1 of 7

I was wondering whether it is possible to run the hist command over the marix rows.
for instance if A=[10 9 8 12 20 21 30 18]
then h=hist(A) will be [3 1 0 0 1 2 0 0 0 1].

Now imagine that A=[10 9 8 12 20 21 30 18;...
                               11 21 1 17 15 11 29 8]
I was wondering whether there is a way to get the hist of this matrix over the element of the rows which for instance in this case give the following result
[3 1 0 0 1 2 0 0 0 1;...
 1 0 1 2 1 1 0 1 0 1]
Thanks in advance for the help

Subject: hist

From: Nathan

Date: 26 Oct, 2009 19:37:28

Message: 2 of 7

On Oct 26, 12:28 pm, "SM " <khanmor...@gmail.com> wrote:
> I was wondering whether it is possible to run the hist command over the marix rows.
> for instance if A=[10 9 8 12 20 21 30 18]
> then h=hist(A) will be  [3     1     0     0     1     2     0     0     0     1].
>
> Now imagine that A=[10 9 8 12 20 21 30 18;...
>                                11 21 1 17 15 11 29 8]
> I was wondering whether there is a way to get the hist of this matrix over the element of the rows which for instance in this case give the following result
> [3     1     0     0     1     2     0     0     0     1;...
>  1     0     1     2     1     1     0     1     0     1]
> Thanks in advance for the help

how about a for loop?

for n=1:size(A,1)
  h(n,:) = hist(A(n,:));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h =
     3 1 0 0 1 2 0 0 0 1
     1 0 1 2 1 1 0 1 0 1

-Nathan

Subject: hist

From: the cyclist

Date: 26 Oct, 2009 19:40:04

Message: 3 of 7

"SM " <khanmoradi@gmail.com> wrote in message <hc4t82$b15$1@fred.mathworks.com>...
> I was wondering whether it is possible to run the hist command over the marix rows.
> for instance if A=[10 9 8 12 20 21 30 18]
> then h=hist(A) will be [3 1 0 0 1 2 0 0 0 1].
>
> Now imagine that A=[10 9 8 12 20 21 30 18;...
> 11 21 1 17 15 11 29 8]
> I was wondering whether there is a way to get the hist of this matrix over the element of the rows which for instance in this case give the following result
> [3 1 0 0 1 2 0 0 0 1;...
> 1 0 1 2 1 1 0 1 0 1]
> Thanks in advance for the help

I don't think there is a one-liner that will do that, but you can just loop over the rows:

>> for nr = 1:size(A,1),
>> h{nr} = hist(A(nr,:))
>> end

Note that I used a cell array to store the results of each HIST command. There are other possibilities.

the cyclist

Subject: hist

From: dpb

Date: 26 Oct, 2009 19:37:37

Message: 4 of 7

SM wrote:
> I was wondering whether it is possible to run the hist command over the marix rows.
...
>
> Now imagine that A=[10 9 8 12 20 21 30 18;...
> 11 21 1 17 15 11 29 8]
> I was wondering whether there is a way to get the hist of this matrix
> over the element of the rows ...

n = hist(A');

--

Subject: hist

From: the cyclist

Date: 26 Oct, 2009 19:52:03

Message: 5 of 7

dpb <none@non.net> wrote in message <hc4u3o$inq$1@news.eternal-september.org>...
> SM wrote:
> > I was wondering whether it is possible to run the hist command over the marix rows.
> ...
> >
> > Now imagine that A=[10 9 8 12 20 21 30 18;...
> > 11 21 1 17 15 11 29 8]
> > I was wondering whether there is a way to get the hist of this matrix
> > over the element of the rows ...
>
> n = hist(A');
>
> --

This is a way to do it as a one-liner, but note that this does NOT give the same result as doing them independently via a loop, because the matrix method uses a common binning for all histograms. This is apparently what the OP wants to avoid.

the cyclist

Subject: hist

From: SM

Date: 26 Oct, 2009 20:29:06

Message: 6 of 7

Thanks guys,
I have one more thing to ask...I also want to define some discard level which is the the most repeated value in each row. For this I am trying to take the maximum occurence of the hist in each row and then find its corresponding value!
But I recieve a dimension mismatch error.
Can you help me with this as well.
Thanks again

Subject: hist

From: the cyclist

Date: 26 Oct, 2009 20:39:03

Message: 7 of 7

"SM " <khanmoradi@gmail.com> wrote in message <hc50qh$ge9$1@fred.mathworks.com>...
> Thanks guys,
> I have one more thing to ask...I also want to define some discard level which is the the most repeated value in each row. For this I am trying to take the maximum occurence of the hist in each row and then find its corresponding value!
> But I recieve a dimension mismatch error.
> Can you help me with this as well.
> Thanks again

In principle, you could use HIST for this, but I would explore the MODE command. If you putter around and cannot figure it out, show us what you have done, and we can try to help some more.

the cyclist

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us