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

3D histogram

312 views
Skip to first unread message

Hana

unread,
Nov 22, 2005, 5:13:37 AM11/22/05
to
Hi,
My question is:
I have a 3D matrix and I want to build a 3D histogram combining the
first and second dimensions of the matrix. I tried this by using
function hist3 in matlab7 but I got an error saying that your matrix
should contain only 2 columns. I am sure that there is a function
that does that but what is it?

regards.
Hana.

Peter Perkins

unread,
Nov 22, 2005, 10:35:29 AM11/22/05
to

HIST3 is intended for creating a histogram over a two-dimensional grid, from 2-D
data. It is exactly the 2-D analog of HIST and HISTC. Don't know what you mean
by, "build a 3D histogram combining the first and second dimensions of the
matrix", but you might also look at BAR3.

Hope this helps.

- Peter Perkins
The MathWorks, Inc.

Hana

unread,
Nov 22, 2005, 1:05:51 PM11/22/05
to
I mean that, for example if we have a(:,:,1)=[1 2 3;3 3 1;3 2 2] and
a(:,:,2)=[1 2 1;3 3 3;1 1 1],then how can we create a 3D histogram
that contains the 9
bins:(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2) and (3,3)?

hope you got the point.
Hana.

Peter Perkins

unread,
Nov 22, 2005, 1:08:43 PM11/22/05
to
Hana wrote:

> I mean that, for example if we have a(:,:,1)=[1 2 3;3 3 1;3 2 2] and
> a(:,:,2)=[1 2 1;3 3 3;1 1 1],then how can we create a 3D histogram
> that contains the 9
> bins:(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2) and (3,3)?

It appears you may mean that a(:,:,1) contains x coords, and a(:,:,2) contains y
coords. I'm guessing that you want some combination of RESHAPE and either
ACCUMARRAY or HIST3, depending on whether or not you want to make a plot. I
still can't tell what it is you are trying to do.

Hana

unread,
Nov 22, 2005, 1:58:50 PM11/22/05
to
Hi,
Thank you for fast respond. It seems that I didn't explain my point
clearly. I will try to give you another example, I have an RGB image
and I want to create a histogram that combines the R and G components
which means that each bin doesnt represent only a single value.
Instead it represents a pair with the first coordinate includes the R
value and the next contains the G value. I dont know how to do this
using matlab6.

hope it is clear.
Hana.

frankouche

unread,
Dec 8, 2005, 7:01:27 AM12/8/05
to

try this :

r=image(:,:,1)
g=image(:,:,2)

% pixels must be in a single column
r2=reshape(r,prod(size(r)),1)
g2=reshape(g,prod(size(g)),1)

% now matrix of 2 columns for hist3
rg=[r2, g2]

%hist 10x10 default, choose bins for hist3 as you want
h2rg=hist3(rg)

Hana

unread,
Dec 8, 2005, 12:08:03 PM12/8/05
to
Thank you. It works for Matlab 7 but what is the equivalent function
to hist3 in matlab 6?

Thanks.
Hanaa.

sankar basu

unread,
Jan 2, 2010, 11:37:02 PM1/2/10
to
Hana <m00...@squ.edu.om> wrote in message <ef1c...@webx.raydaftYaTP>...

Hi,
I have a few n cross 3 matrices whose entries are some specific inter-vector angles ranging from 0 to 180 degrees. I wish to split each column in six 30-degree bins (0-30, 30-60, ...150-180) and wish to plot a frequency distribution profile for each of such matrices. As per as I understand, it may be termed a 4-D histogram where the first three dimensions are the three parameters represented by the three columns of the matrix and the forth one should be a RGB color code specifying the frequency of each 3D-bin (e.g, constituted by X-bin: 30-60, Y-bin: 60-90, Z-bin: 0-30). Any suggestions would be great help.

sankar basu

unread,
Jan 2, 2010, 11:40:06 PM1/2/10
to
Hana <m00...@squ.edu.om> wrote in message <ef1c...@webx.raydaftYaTP>...

Hi,

ImageAnalyst

unread,
Jan 3, 2010, 12:19:15 AM1/3/10
to
Can you explain better what this means: "the forth one (column) should

be a RGB color code specifying the frequency of each 3D-bin"

Do you want a histogram count (frequency), or do you want a color
(which would be a 3 element number by the way, not a single one)? To
me, it seems like you're mixing the concepts.

sankar basu

unread,
Jan 3, 2010, 1:31:02 PM1/3/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <5a01a867-7949-4231...@m16g2000yqc.googlegroups.com>...

Since all three axes in this essentially 3D plot already represents three (angular) parameters (e.g, parameter X,Y,Z), its only different colors that can now describe the frequency of each 3D-bin. Like 2D Histograms in matlab, I suppose an array of RGB color codes could be pre-defined here also, each of which will be representing a range of percentage occupancy. e.g, if a bin consists of 10% of the total population it will be represented by blue, 20% by red, 30% by green and like that. Then the function will simply distribute the numbers in as many bins according to the user's choice (e.g, in my specific case, 6 * 6 * 6 = 216 3D-bins ), then count the frequency in each 3D-bin, normalize against the total population and put colors from the color-code array to each of the 3D-bins, appropriate to their percentage occupancy. I hope I am understood this time.

ImageAnalyst

unread,
Jan 3, 2010, 8:52:16 PM1/3/10
to
I think you can just compute your 3D histogram and the use scatter3()
to plot it and then set the CData property to do the marker coloring.
0 new messages