Histogram with different sized bins and edges to illustrate wave periods
3 次查看(过去 30 天)
显示 更早的评论
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247508/histogram.jpeg)
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!
0 个评论
采纳的回答
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 Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!