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

5 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by