Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Normalization of 3D Histogram

779 views
Skip to first unread message

David

unread,
Apr 2, 2012, 4:00:13 PM4/2/12
to
Hi everybody,

I would like to ask for help with normalization of "hist3" - is it possible and How? I read some posts, but they firstly calculate histogram by hist3, then multiply the result and finally display it by "surf" function - but it's not fine for me. I need X-Y view with rectangular cells which makes "hist3" at X-Y view but it must be normalized (0,1).

Can you help me, please?

David

Filip Trönnberg

unread,
Apr 13, 2012, 10:28:10 AM4/13/12
to
Hi David!

I acctually have the same kind of problem. I've yet to figure it out but what I've done is to create a surface:

[P bins] = hist3(X,[25 25]);
surf(P/sum(sum(P)));

The problem is then that the axes for the surf-plot goes from 0:25 which is not really what I wanted. but the z-axes is atleast normalized. Please let me know if you find a good way to do this´!

David

unread,
Apr 14, 2012, 7:05:14 AM4/14/12
to
Hi Filip,

finally a did it as follows: (data_x and data_y are values, which you want to calculate at hist3)

x = min_x : step : max_x; % axis x, which you want to see
y = min_y : step : max_y; % axis y, which you want to see

[X,Y] = meshgrid(x,y); % important for "surf" - makes defined grid

pdf = hist3([data_x , data_y],{x y}); % standard hist3 (calculated for yours axis)
pdf_normalize = (pdf ' ./ length(data_x); % normalization means devide it by length of
% data_x (or data_y)
figure()
surf(X,Y,pdf_normalize)

Is it helpful for you?

Filip Trönnberg

unread,
Apr 14, 2012, 10:09:29 AM4/14/12
to
Thank you, thank you, tank you!!! That is exactly what I wanted!! :)

If I now want to use this as a distribution to draw values from, do you know of a good way to do this?

Best regards!
Filip

David

unread,
Apr 14, 2012, 1:12:21 PM4/14/12
to
you're welcome :-)

> If I now want to use this as a distribution to draw values from, do you know of a good way to do this?

I'm sorry, but I don't understand your question - you want to draw the distribution function? because "hist3" plot dependence of two variables (3D graph), but the distribution function is only for one.

Filip Trönnberg

unread,
Apr 14, 2012, 7:21:18 PM4/14/12
to
Sorry, I didn't explain myself very well.

What I wanted to do was to use this "custom" distribution and use it to draw random variables from it. Much like it is possible to use MATLAB's function "randn" to get normally distributed random numbers.

Say that I know that the x value (ask queue size) to be 5000 and I want to use this distribution to get a "random" value for y (bid size queue).
Did I make myself clear this time? :/

I'm not very familiar to neither the math regarding probabilities or using MATLAB in this fashion so sorry if it is a stupid question! But if I have understood it correctly, using the code snippet you provided, gave me a probability density function. Which, if I integrate over it, yields 1.0 as the step size approches 0.

Yusuke

unread,
Oct 30, 2012, 3:12:08 AM10/30/12
to
Hi David,

I think if you want to compute the probability density distribution, you need to normalized it using the area of the bin too. In your code,

pdf_normalize = (pdf / (length(data_x)*step^2) );

should work.

"David" wrote in message <jmblla$cau$1...@newscl01ah.mathworks.com>...
0 new messages