Histogram with different sized bins and edges to illustrate wave periods

2 ビュー (過去 30 日間)
Henning Eimstad
Henning Eimstad 2019 年 11 月 9 日
コメント済み: Henning Eimstad 2019 年 11 月 12 日
I have a set of data (waveperiods) with corresponding number of observations as seen below.
waveperiods = [9 10 11 12 13 14 15 16 17 18 19 20 21]
observations = [1 5 14 22 28 5 6 2 1 0 1 0 0]
i.e a period of 9 is observed 1 time, and a period of 10 is observed 5 times etc....
I would like to make a histogram of the data, BUT with like a class system.
class 1 should contain all periods between 0 and 9.5
class 2 should contain all periods between 9.5 and 10.5 etc...
class 9 should contain all periods between 16.5 and 30.
Then the histogram should be nice and normal-ish like in the picture below.
histogram.jpg
However, I dont understand how to control the edges and make the desired groups...
I am stuck with the following code:
waveperiods = [9:21];
observations = [1 5 14 22 28 5 6 2 1 0 1 0 0];
groups = [0 9.5:1:16.5 30]; %Ive tried to make the intervals/groups....
Please help, thanks!

採用された回答

Ajay Pattassery
Ajay Pattassery 2019 年 11 月 12 日
The following code will plot the above bar graph
waveperiods = (9:21);
observations = [1 5 14 22 28 5 6 2 1 0 1 0 0];
groups = [0 9.5:1:16.5 30];
obsInRange = zeros(1,length(groups)-1);
rangeLength = length(groups)-1;
for i=1:rangeLength
waveperiodsIndex = waveperiods >= groups(i) & waveperiods < groups(i+1);
obsInRange(i) = sum(observations(waveperiodsIndex));
end
bar(1:rangeLength,obsInRange);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by