Thread Subject: hist with predifined edges

Subject: hist with predifined edges

From: Ioannis Botonakis

Date: 9 Mar, 2011 16:55:06

Message: 1 of 6

Hallo!

Can you please tell how to get a histogram with the following edges:

edges = [0 200 350 500 800 ceil(max(data))];

It seems that the hist or the histc functions do not work.

Sincerely
I. Botonakis

Subject: hist with predifined edges

From: Steven_Lord

Date: 9 Mar, 2011 17:54:46

Message: 2 of 6



"Ioannis Botonakis" <i.botonakis_withoutthis_@googlemail.com> wrote in
message news:il8bda$ndo$1@fred.mathworks.com...
> Hallo!
>
> Can you please tell how to get a histogram with the following edges:
>
> edges = [0 200 350 500 800 ceil(max(data))];
>
> It seems that the hist or the histc functions do not work.

HISTC should work -- show the group a SMALL sample of your data and the
exact commands you're using. Then describe what the code does differently
from how you expect/want it to behave.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: hist with predifined edges

From: ImageAnalyst

Date: 9 Mar, 2011 19:20:37

Message: 3 of 6

On Mar 9, 11:55 am, "Ioannis Botonakis"
<i.botonakis_withoutth...@googlemail.com> wrote:
> Hallo!
>
> Can you please tell how to get a histogram with the following edges:
>
> edges = [0 200 350 500 800 ceil(max(data))];
>
> It seems that the hist or the histc functions do not work.
>
> Sincerely
> I. Botonakis

-----------------------------------------------------------------------------------------------
Funny, histc() seemed to work for me. You might need to call tech
support or issue the command "which -all histc" to see if you've
redefined histc. Because with my code it works fine:

% Generate some sample data.
data = 2000*rand(1,100000);
edges = [0 200 350 500 800 ceil(max(data))];
% Take the histogram.
counts = histc(data, edges)
bar(counts);
set(gca,'XGrid','off','YGrid','on');
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Label axes.
ylabel('Counts', 'FontSize', fontSize);
xlabel('Bins', 'FontSize', fontSize);
% Label the bins (tick marks).
for bin = 1: length(edges)-1
x_labels{bin} = sprintf('%d - %d', ...
edges(bin), edges(bin+1));
end
x_labels{bin+1} = ' ';
set(gca,'XTickLabel', x_labels, 'FontSize', fontSize);

Subject: hist with predifined edges

From: Think two, count blue.

Date: 9 Mar, 2011 19:32:11

Message: 4 of 6

On 11-03-09 10:55 AM, Ioannis Botonakis wrote:

> Can you please tell how to get a histogram with the following edges:
>
> edges = [0 200 350 500 800 ceil(max(data))];
>
> It seems that the hist or the histc functions do not work.

In addition to what the others have said:

If you are going to be using ceil(max(data)) then you should use inf
(infinity) instead. Otherwise you end up with a situation where the last bin
counts values that are equal to the maximum if the maximum _happens_ to be
integral, but where the last bin counts nothing at all if the maximum happens
to have a non-zero fractional part.

Subject: hist with predifined edges

From: Ioannis Botonakis

Date: 10 Mar, 2011 12:09:05

Message: 5 of 6

"Steven_Lord" <slord@mathworks.com> wrote in message <il8esi$a9k$1@fred.mathworks.com>...
>
>
> HISTC should work -- show the group a SMALL sample of your data and the
> exact commands you're using. Then describe what the code does differently
> from how you expect/want it to behave.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Dear Mr. Lord,

thank for your answer. I expressed my question incorrectly. I want also the width of the bar columns to be the differnce of the edges. For example:
When the edges are [0 200 350 500 800 ceil(max(data))], then I want that the bin widths are: 200-0=200; 350-200=150; 500-350=150; 800-500 = 300 and so on. Is this possible?

Sincerely
I. Botonakis

Subject: hist with predifined edges

From: ImageAnalyst

Date: 10 Mar, 2011 18:08:10

Message: 6 of 6

On Mar 10, 7:09 am, "Ioannis Botonakis"
<i.botonakis_withoutth...@googlemail.com> wrote:
> thank for your answer. I expressed my question incorrectly. I want also the width of the bar columns to be the differnce of the edges. For example:
> When the edges are [0 200 350 500 800 ceil(max(data))], then I want that the bin widths are: 200-0=200; 350-200=150; 500-350=150; 800-500 = 300 and so on. Is this possible?
>
> Sincerely
> I. Botonakis
---------------------------------------------------
You're going to have to get the handles of the individual bars with
findobj() if you want bars of different widths. I believe that bar()
and the various hist functions all have equal width patches for the
bars, even though the bars represent different width ranges of your
data.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
hist Ioannis Botonakis 9 Mar, 2011 11:59:05
histc Ioannis Botonakis 9 Mar, 2011 11:59:05
edges Ioannis Botonakis 9 Mar, 2011 11:59:05
rssFeed for this Thread

Contact us at files@mathworks.com