How to create a frequency distribution table
26 views (last 30 days)
Show older comments
I have hourly recorder data for wave height and wave direction, so I want to create a frequency distribution table for this data by grouping it.
Maybe the attached picture explains what I need exactly.
Appreciate your help .
1 Comment
Mathieu NOE
on 13 Mar 2023
Look for heatmap topics / examples on this forum and on the File exchange
Answers (1)
Drew
on 4 May 2023
Edited: Drew
on 4 May 2023
From the raw data, you can use histcounts2 (https://www.mathworks.com/help/matlab/ref/histcounts2.html) to get the number of data points that fall in each joint occurrence bin. You can control the bin edges, etc, if desired. A similar question was answered with histcounts2: https://www.mathworks.com/matlabcentral/answers/268207-how-to-bin-data-based-on-two-variables-to-create-a-joint-occurance-table?s_tid=prof_contriblnk
Once you have the counts, you can normalize them and visualize them in various ways, including with heatmap, hist3, or with histogram2. If using a heatmap, you can adjust the heatmap chart properties with https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.heatmapchart-properties.html
% jotw = Joint Occurrence Table for Waves
% This is data from the image above
jotw=[1.1 0.3 0 0 0 0 0 0 0 0.1 0.4 1.4
1.8 1.2 0.3 0.1 0 0.7 0 0 0.1 0.1 2.1 3.1
1.8 1.9 0.3 0 0 0 0 0 0 0.5 5.3 5.8
1.6 1.2 0 0 0 0 0 0 0 0.7 5.9 7.4
0.6 0.2 0 0 0 0 0 0 0 0.5 5.9 6.0
0.4 0.2 0 0 0 0 0 0 0 0.6 4.0 6.6
0.3 0 0 0 0 0 0 0 0 0.5 2.8 6.0
0.2 0 0 0 0 0 0 0 0 0.5 2.3 2.9
0 0 0 0 0 0 0 0 0 0.4 2.1 2.0
0 0 0 0 0 0 0 0 0 0.2 1.2 1.1
0 0 0 0 0 0 0 0 0 0.2 1.0 0.9
0 0 0 0 0 0 0 0 0 0 0.8 0.4
0 0 0 0 0 0 0 0 0 0 0.6 0.2
0 0 0 0 0 0 0 0 0 0 0.4 0.2
0 0 0 0 0 0 0 0 0 0 0.4 0.1
0 0 0 0 0 0 0 0 0 0 0.7 0.3
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0];
% Change zeros to NaNs so that the zeros can be made invisible
jotw(jotw==0)=NaN;
h=heatmap(jotw);
% Adjust the label and color of the NaNs
h.MissingDataLabel="no data";
h.MissingDataColor=h.Colormap(1,:);
% Can alternately get these from the bin centers or bin edges if the data
% is from histcounts2
h.XData={'0','30','60','90','120','150','180','210','240','270','300','330'};
h.YData={'0.0-0.2','0.2-0.2','0.4-0.6','0.6-0.8','0.8-1.0','1.0-1.2','1.2-1.4', ...
'1.4-1.6','1.6-1.8','1.8-2.0','2.0-2.2','2.2-2.4','2.4-2.6','2.6-2.8', ...
'2.8-3.0','3.0-4.0','4.0-5.0','>5.0'};
% Add some labels
h.XLabel='Mean Wave Direction';
h.YLabel='Significant Wave Height (m)';
h.Title='% Occurrence of Wave Height and Wave Direction';
0 Comments
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!