Binning x and y
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi all,
Assuming that I have the follwing data:
x=[0, 2, 2.4, 2.8, 3.4, 3.9, 4, 4,7, 5.3, 5.8, 6, 6.4......]; % unit of x is cm
y=[100, 50, 30, 25, 20, 16, 14, 13, 12, 11, 10.5, 10, ....]; % Intensity
My question is the following:
I can plot y vs. x but I Would like, for instance, to bin x with a constant bin width (constant distance). Let say bin width of 2 (constant distance 2 cm). Therefore I would like to obtain a new x called xn:
xn=[0, 2, 4, 6,..]
and yn should contain the sum of the data which are conatained in in each interval:
interval1=[0,2] contains 100+50=150
interval2=]2,4] contains 50 + 30 + 25 + 20 + 16 + 14 =155
interval3=]4,6] contains 56.5
yn=[150, 155, 56.5]
and then I would like to plot yn versu xn
your hepl is highly welcome....
cheers
댓글 수: 0
답변 (1개)
the cyclist
2014년 8월 5일
You should be able to do this with the hist() or histc() command. You can specify your bin locations, and then get the index for which x values went into each bin. Then use that index to sum your y values.
댓글 수: 5
the cyclist
2014년 8월 26일
I suppose it is either
- the way the bin edges are defined, they are not centered around zero, OR
- the way MATLAB treats values that are exactly on the bin edge, it consistently puts them to one side, leading to asymmetry.
laura9510
2017년 1월 31일
Jumping in years later but if I was looking to average within bins, is using accumarray possible in conjunction with another function?
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!