Histogram with overlapping bins --> summing second argument

Hi,
I've got the following code:
load data.txt;
X = data(:,1);
Y = data(:,2);
m = [-60:1:12000];
k = [m; m+200]; % m+x: x is the width of the bin
NrEvents = NaN(1,size(k,2));
for i=1:length(NrEvents)
NrEvents(i) = sum (X<=k(2,i) & X>=k(1,i) );
end
Like this I can calculate the number of data points for overlapping bins. Now I'd like to add another argument, summing the corresponding numbers written in column 2 of the data file for the same bins. I assume it works with 'cumsum' but I'm unable to find a way to kind of link 'cumsum' with the 'sum' function. Probably not a big thing...
Thanks for any help Stefanie

 채택된 답변

Daniel Shub
Daniel Shub 2011년 8월 12일

0 개 추천

Starting from what you have, and I am not sure that is advisable:
SumY(i) = sum (Y(X<=k(2,i) & X>=k(1,i)));

추가 답변 (1개)

Stef 24
Stef 24 2011년 8월 12일

0 개 추천

Great, already worked. The cumsum might have messed it up...
Thanks

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

질문:

2011년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by