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:
how histc works ?

Subject: how histc works ?

From: grandfather

Date: 2 Oct, 2007 15:25:15

Message: 1 of 4

I am very newbie in matlab, so I read the matlab help topic for histc function but I couldn't understand it.
I suppose an A vector of these values [2; 23; 100; 255; 255], then I apply

edges=[4; 255]
histc(A,edges)

and what I get is

ans=[2; 2]
what does histc funtion ??

Subject: how histc works ?

From: Adam

Date: 2 Oct, 2007 16:33:59

Message: 2 of 4

grandfather <dimpallas@gmail.com> wrote in message
<16976228.1191338746402.JavaMail.jakarta@nitrogen.mathforum.org>...
> I am very newbie in matlab, so I read the matlab help
topic for histc function but I couldn't understand it.
> I suppose an A vector of these values [2; 23; 100; 255;
255], then I apply
>
> edges=[4; 255]
> histc(A,edges)
>
> and what I get is
>
> ans=[2; 2]
> what does histc funtion ??

>> help histc
 HISTC Histogram count.
    N = HISTC(X,EDGES), for vector X, counts the number of
values in X
    that fall between the elements in the EDGES vector
...
N(k) will count the value X(i) if EDGES(k) <= X(i) < EDGES(k+1).


So it's looking for values in the range [4, 255) and [255, 255]

if the last value in edges is not equal to any elements in A
then it will be zero.

Perhaps a more interesting example.
A = randn(1, 10000);
edges = [-4:0.01:4];
ans = histc(A, edges);
bar(edges, ans)

if you're specifying edges use histc(), if you're specifying
centers use hist()

~Adam

Subject: how histc works ?

From: Jerome Briot

Date: 2 Oct, 2007 20:21:05

Message: 3 of 4

Hi,

from the documentation :

"n(k) counts the value x(i) if edges(k)
<= x(i) < edges(k+1). The last bin counts any values of x that
match edges(end). Values outside the values in edges are
not counted."

So there are 2 elements of A (23, 100) between 4 and 255 (not included).
And there are also 2 elements (255, 255) that match 255.

Jérôme

Subject: Como o histc funciona?

From: Howard

Date: 6 Jun, 2014 18:23:12

Message: 4 of 4

clear all
close all
A = [1;3;2;6;4;15;17;23;29;34;20];
edges = [0;10;20;30];
ans = histc(A, edges);
figure
bar(edges, ans)

%Ver o gráfico: Existem 5 valores que caíram no intervalo [0,10). 2 valores
%que caíram no intervalo [10,20) e há 3 valores em [20,30). Nenhum valor caiu
%exatamente no 30. O valor 34 não caiu em nenhum desses intervalos.

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