How do I create discrete intervals, sum relevant data and produce a histogram?
이전 댓글 표시
I want to create a histogram. I have two variables x and y. I want the data to be binned into regular intervals based on x values, but frequency to be calculated as the sum of Y for all X values in each interval.
Example data
if true
% code
end
Y= [1, 1.1, 1.8, 0.7, 1.2, 1.7, 0.1]
X= [15, 21, 12, 24, 5, 34, 38 ]
We sort by X and place into discrete intervals of 0-10,10-20,20-30,30-40 We then sum the Y values within the intervals defined by X
if true
% code
end
For x=0-10 Sum
1.2 = 1.2
For x=10-20
1.8 + 1 = 2.8
For x=20-30
1.1 + 0.7 =1.8
For x=30-40
1.7+0.1 =1.8
Then plot/histogram interval vs sum of y
end
Thank you in advance!!
댓글 수: 2
When you use the {} Code button it inserts some sample code like this:
if true
% code
end
but actually you do not need to keep this: all you need are the two spaces at the start of each line. You can edit your question and remove those superfluous lines of code and it makes your code easier to read because it is less confusing!
tatyana gabellone
2015년 5월 11일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!