how to bin data based on two variables to create a joint occurance table?

15 views (last 30 days)
Hi everyone, I have only recently started to use MATLAB so please be patient, I'm sorry if I have trouble explaining myself properly.
I am trying to analyse the wave resource off the Isles of Scilly.
I have a huge structure array and I wish to sort the data into a table that shows how often conditions occur within bin ranges for two variables. i.e how often wave heights are between 3 - 3.5 meters whilst wave period is between 5 - 5.5 seconds. In this case the variables are called H and T.
H =[data(:,1).Hsig]<br>
T = [data(:,1).Tm_10]<br>
I have created one table so far using a simple for loop;
for i=0:0.5:10
m = [sum(H>=i & H<i+0.5 & T>=1.5 & T<2)]
end
However, obviously this only changes the height and I have manually changed the T values and run the program again whilst noting down the values each time. As you can see this is ridiculously crude and time consuming and I have 12 more tables to create, (one for each location).
Can anybody advise on how I can bin the data based on changing H and T values at the same time.
I realise I have explained this poorly, and I have attached a screen shot of the first table I have created to hopefully show what I am trying to do.
Any help will be immensely appreciated.
James

Accepted Answer

Guillaume
Guillaume on 15 Feb 2016
If you have matlab 2015b, you can simply use histcounts2:
h = histcounts2(H, T, 0:0.5:10, 1.5:0.5:12)
  3 Comments
j atkinson
j atkinson on 15 Feb 2016
yeah, works perfectly and so simple!! thank you very much, I owe you many hours of my time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!