Construct a Histogram plot using directional bins

13 views (last 30 days)
I need to create a scatter table representing the proportional frequency of different sea states. For this I have 3 arrays (Hs_10yr, Te_10yr and Dir_10 yr). I nedd a scatter table with bins using the parameters Hs and Te but for different directional bins (windows). I already have the script for scatter table but I don't know how to set the condition for example to get a table for Dir = 180: 270 degree.How can I obtain this?
hFig = figure;
hAxes = axes(hFig);
xVals = Te_10yr;
yVals = Hs_10yr;
xEdges = 1:0.5:12.5;
yEdges = 0:0.5:4.5;
%yEdges = min(yVals):0.5:max(yVals);
hist_Counts = histcounts2(xVals,yVals,xEdges,yEdges);
hist_Counts_normalized = (hist_Counts / sum(hist_Counts,'all'))*100;
hHist = histogram2(hAxes,'XBinEdges',xEdges,'YBinEdges',yEdges,'DisplayStyle','tile','BinCounts',hist_Counts_normalized);
colormap(colorMap_occ);
colorbar;
xBinCenters = hHist.XBinEdges - [0,diff(hHist.XBinEdges)/2];
yBinCenters = hHist.YBinEdges - [0,diff(hHist.YBinEdges)/2];
for i = 2:numel(xBinCenters)
for j = 2:numel(yBinCenters)
x_loc = xBinCenters(i);
y_loc = yBinCenters(j);
if ~(round(hHist.Values(i-1,j-1),4) == 0)
text(hAxes,x_loc,y_loc,[num2str(round(hHist.Values(i-1,j-1),3),'%4.3f'),'%'],'Color',[0 0 0],'FontSize',9,'FontWeight','bold','HorizontalAlignment', 'center');
else
continue
end
end
end
box(hAxes,'on');
grid(hAxes,'on');
axis(hAxes,'tight');
hold(hAxes,'off');
  2 Comments
Steven Lord
Steven Lord on 23 Apr 2020
What do you mean when you use the term "different directional bins (windows)"? Do you mean you want to have bins along x and y that are different widths? That's not going to be hard to do.
Do you have a picture of what you're hoping to receive as the end result? It kind of looks from your text calls like you want a heatmap but I'm not 100% sure.
Iulia Anton
Iulia Anton on 23 Apr 2020
Yes it is a heatmap. To be more exactly I want to filter data that apears in heatmap (Hs and Te) depending the Dir variable. I don't need Dir to appear in my heatmap. It is used only to filter data (Hs and Te). So the variable Dir is between 0 and 360 and I need to get data of Hs and Te only for Dir between 90 and 180.

Sign in to comment.

Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!