if i have data a and i want to mean or average every 10 values as 1:10, 2:11, 3:12 and as so on for length of data ?

 採用された回答

Walter Roberson
Walter Roberson 2016 年 8 月 21 日

0 投票

mean(reshape(YourData, 10, []))

8 件のコメント

yasmeen hadadd
yasmeen hadadd 2016 年 8 月 21 日
Thank you so much
yasmeen hadadd
yasmeen hadadd 2016 年 8 月 21 日
But i need overlap between the values as 1:10 then from 2:11 and so on
Mudassir Rafi
Mudassir Rafi 2016 年 8 月 21 日
編集済み: Walter Roberson 2016 年 8 月 21 日
arr=1:100;
for i=1:91
a=(arr(i:i+9));
mean(a)
end
yasmeen hadadd
yasmeen hadadd 2016 年 8 月 21 日
please solve this error "Index exceeds matrix dimensions".
Mudassir Rafi
Mudassir Rafi 2016 年 8 月 21 日
value of i should be 9 less than the last dimension of array (i.e.a in your case)
Walter Roberson
Walter Roberson 2016 年 8 月 21 日
cs = cumsum(YourData);
moving_average = (cs(10:end) - cs(1:end-9))/10;
Andrei Bobrov
Andrei Bobrov 2016 年 8 月 21 日
Hi Walter! Small correcting.
cs = cumsum(YourData(:));
moving_average = (cs(10:end) - [0;cs(1:end-10)])/10;
Walter Roberson
Walter Roberson 2016 年 8 月 21 日
Thanks, Andrei

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

その他の回答 (2 件)

Star Strider
Star Strider 2016 年 8 月 21 日

0 投票

‘But i need overlap between the values as 1:10 then from 2:11 and so on’
Use a moving average filter:
Heart_pulse_avg = filter(ones(1,10), 10, Heart_pulse);

1 件のコメント

Steven Lord
Steven Lord 2016 年 8 月 21 日
Use the movmean function if you're using release R2016a or later.

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

Andrei Bobrov
Andrei Bobrov 2016 年 8 月 21 日

0 投票

a - your vector;
out = movsum(a,[0 9],'Endpoints','discard')/10;

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by