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 a=0-5,6-10,11-15,16-20 with the corresponding average and standard deviation of b. Please help me with a easy way since the series are very large?

 採用された回答

Star Strider
Star Strider 2015 年 9 月 15 日
編集済み: Walter Roberson 2015 年 9 月 15 日

0 投票

This seems to work:
m = [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];
binedge = 0:5:20; % Define Bin Edges
[acount, idx] = histc(m(:,1), binedge); % Bin ‘a’, Return Index Vector
meanb = accumarray(idx+1, m(idx+1,2), [], @mean); % Get Mean Of Corresponding ‘b’
figure(1)
bar(binedge, acount, 'histc')
grid
One of the bin edge values is zero, and that doesn’t work as an index for accumarray, so I added 1 to the index values. That doesn’t affect the calculation.

4 件のコメント

trailokya
trailokya 2015 年 9 月 16 日
Sir how to get the corresponding standard deviation like mean?
trailokya
trailokya 2015 年 9 月 16 日
編集済み: Star Strider 2015 年 9 月 16 日
i think it should be
stdb = accumarray(idx+1, m(idx+1,2), [], @std);
Star Strider
Star Strider 2015 年 9 月 16 日
I didn’t specifically test the code for the standard deviation, but it should work as you wrote it, providing there are no NaN values in your data.
Star Strider
Star Strider 2015 年 9 月 16 日
If my Answer solved your problem, please Accept it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by