# frequency of a specific wind direction in a histogram with hourly intervals

1 view (last 30 days)
Dimitrios Bentis on 27 Apr 2017
Hello,
I have 2 vectors (datetime, wind direction). How could i plot a histogram with 2 hour bins (0-2,2-4...22-24) showing the frequency of the wind direction being between 100 and 150 degrees during each of the above intervals.
Thank you very much!
Will Nitsch on 2 May 2017
Try this:
%%create a bunch of random data
times = [];
windDir = [];
for i = 1:10
times = [times,randperm(24)];
% Note that not all wind directions will be between 100-150 deg
windDir = [windDir, rand(1,24)*360];
end
%%Get the winds with a direction between 100 and 150:
windsIdx = find(windDir <= 150 & windDir >= 100);
hFig = figure;
counts = histcounts(times(windsIdx),[0,2,4,6,8,10,12,14,16,18,20,22,24]);
hHist = histogram('Categories',{'0:00-2:00','2:00-4:00','4:00-6:00','6:00-8:00','8:00-10:00','10:00-12:00','12:00-14:00','14:00-16:00','16:00-18:00','18:00-20:00','20:00-22:00','22:00-24:00'},'BinCounts',counts);
Dimitrios Bentis on 3 May 2017
Thanks! It works fine!