Average of array element at defined interval

2 ビュー (過去 30 日間)
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 24 日
回答済み: prem matlani 2020 年 3 月 21 日
Suppose,
a=[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
i want to calculate average of group of five nos. so that my resulting array is like
avg=[3 3 3 3]
Can any one help me for the same.
  2 件のコメント
Adam
Adam 2015 年 3 月 24 日
What does four-four nos. mean? Judging from your example I assume you want the average of groups of 5 numbers. Or do you want 4 averages, irrespective of how many elements fall into the four subsections of your array (whose length may not be divisible by 4)
Nikhil Chourasia
Nikhil Chourasia 2015 年 3 月 25 日
Sorry Adam i have written four-four by mistake. I have now edited my question

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

採用された回答

Star Strider
Star Strider 2015 年 3 月 24 日
Use the rehaspe function, then mean, since it takes the means of columns as its default behaviour:
a=[1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5];
ar = reshape(a, [], 4)
ar_mean = mean(ar)
produces:
ar =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
ar_mean =
3 3 3 3
  4 件のコメント
Stelios Fanourakis
Stelios Fanourakis 2019 年 5 月 13 日
I think this is what I need. But why I get NaN values when I am using this line
AxesH = set(gca,'XTick',(0.099:1:37.9))
e = double(AxesH)
ar = reshape(e, [], 2)
ar_mean = mean(ar)
Star Strider
Star Strider 2019 年 5 月 13 日
Look at ‘AxesH’. It may be empty,or have no numeric values.

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

その他の回答 (1 件)

prem matlani
prem matlani 2020 年 3 月 21 日
High,
I have collected data from a source and it clearly shows that there has been some tests at specific points in the x axis (1100, 900, 650, 420, 200) approx, how can i filter this data to get rid of the noise within the ranges

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by