From: Ben Williams on
Hi,

I have a question about binning data. Binning data x data, y data and z data seperately is very straightforward. However I would like to be able to bin x,y,z data in a sort of 3D sense.

In my instance, I have a time series of wave data and I want to create a table that counts the number of times withing the wave record that a wave condition fulfils a unique combination of my Hm0,Tp,MWD bins.

Bin_Hm0 = 0:0.5:1.0;
Bin_Tp = 0:1:2;
Bin_MWD = 0:10:20;

For example;

Hm0 Tp MWD Obs
==============
0 1 10 1
0.5 1 10 3
1.0 1 10 10
0 2 10 2
0.5 2 10 45
1.0 2 10 12
0 1 20 13
0.5 1 20 2
1.0 1 20 24
0 2 20 47
0.5 2 20 23
1.0 2 20 6
..... etc

Has anyone done an exercise like this before? Is there a function that I could use in Matlab that would allow me to make such a histogram?

Best regards,

Ben
From: John D'Errico on
"Ben Williams" <benjamin.williams(a)remove.this.plymouth.ac.uk> wrote in message <huo8i7$j3j$1(a)fred.mathworks.com>...
> Hi,
>
> I have a question about binning data. Binning data x data, y data and z data seperately is very straightforward. However I would like to be able to bin x,y,z data in a sort of 3D sense.
>
> In my instance, I have a time series of wave data and I want to create a table that counts the number of times withing the wave record that a wave condition fulfils a unique combination of my Hm0,Tp,MWD bins.
>
> Bin_Hm0 = 0:0.5:1.0;
> Bin_Tp = 0:1:2;
> Bin_MWD = 0:10:20;
>
> For example;
>
> Hm0 Tp MWD Obs
> ==============
> 0 1 10 1
> 0.5 1 10 3
> 1.0 1 10 10
> 0 2 10 2
> 0.5 2 10 45
> 1.0 2 10 12
> 0 1 20 13
> 0.5 1 20 2
> 1.0 1 20 24
> 0 2 20 47
> 0.5 2 20 23
> 1.0 2 20 6
> .... etc
>
> Has anyone done an exercise like this before? Is there a function that I could use in Matlab that would allow me to make such a histogram?
>

Why not just make three calls to histc? Do it one
time for each variable.

(Look at the second return argument to histc.

Then, once you know where each point lies in each
dimension, aggregate all the counts into one array
using a single call to accumarray.

HTH,
John
From: Walter Roberson on
Ben Williams wrote:

> I have a question about binning data. Binning data x data, y data and z
> data seperately is very straightforward. However I would like to be able
> to bin x,y,z data in a sort of 3D sense.

> Has anyone done an exercise like this before?

The below should be fairly close:

Indices = 1 + ...
floor((x - min(x)) / (max(x) - min(x)) * XBINS) * YBINS * ZBINS + ...
floor((y - min(y)) / (max(y) - min(y)) * YBINS) * ZBINS + ...
floor((z - min(z)) / (max(z) - min(z)) * ZBINS);
TheHistogram = accumarray(Indices,1);
From: Bruno Luong on
Here is a canned function:

http://www.mathworks.com/matlabcentral/fileexchange/23897-n-dimensional-histogram

Bruno