How to determine average and standard deviation of y axis values for corresponding bin of x axis?

조회 수: 8 (최근 30일)
Sir i have two data series say
a b
25.36737061 -27.47956892
20.54391479 -23.68162398
16.76391602 -16.65254461
9.47177124 -19.20600915
16.25158691 -18.56570783
4.462646484 -14.39363913
7.785919189 -14.98048449
12.27481079 -18.49125231
4.851806641 -19.91135093
2.111236572 -5.049334665
-1.457702637 -6.51219601
1.85055542 -1.299793246
and i want to plot for bin width of 'a' (say 5,10,15 etc) with the corresponding average and standard deviation of b. Please help me with a easy way since the series are very large?
  댓글 수: 5
Kelly Kearney
Kelly Kearney 2015년 9월 16일
To simplify the tracking of indices, you may want to look at this aggregatehist.m function... it's basically a wrapper around the histc plus accumarray method demonstrated by Star Strider and myself.
ab = [...
25.36737061 -27.47956892
20.54391479 -23.68162398
16.76391602 -16.65254461
9.47177124 -19.20600915
16.25158691 -18.56570783
4.462646484 -14.39363913
7.785919189 -14.98048449
12.27481079 -18.49125231
4.851806641 -19.91135093
2.111236572 -5.049334665
-1.457702637 -6.51219601
1.85055542 -1.299793246];
bin = -5:5:30;
[aa,bb] = aggregatehist(bin, ab(:,1), ab(:,2));
dev = cellfun(@std, bb);
avg = cellfun(@mean, bb);
amid = (bin(1:end-1)+bin(2:end))./2;
plot(ab(:,1), ab(:,2), '.');
hold on;
errorbar(amid, avg, dev, 'linestyle', 'none', 'marker', 'o');
set(gca, 'xtick', bin, 'xgrid', 'on');

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2015년 9월 16일
Why do you say (the badly-named) "a" is the bin width and then say it has values of 5, 10, or 15 when it clearly does not have any of those values? You can specify the edges of the bins so that the bin widths are exactly what you want. Like if you want a bin width of a(1), which is 25.3673, then you can do
edges = 0 : a(1) : 50
and then pass edges into histc() or histcounts().
  댓글 수: 5
Image Analyst
Image Analyst 2019년 9월 22일
Thanks Wade. Maybe so, since I seem to be immortal, what with my responses of long ago living forever. You can "vote" for answers if you want to give anybody additional "reputation points".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by