Moving Average with timestep

13 ビュー (過去 30 日間)
MakM
MakM 2022 年 2 月 8 日
編集済み: Jan 2022 年 2 月 9 日
I have an array M=[1,4,7,6,4.5,7.5,8.5,4.5] and for time t=[1,2,3,4,5,6,7,8]. I have to find the average of M w.r.t t, with a window size of 2 and step size of window should be 1 or 2. How can I do that?
I am using movmean function to calculate the average, how can I used the window and the step size in this function?
  13 件のコメント
Jan
Jan 2022 年 2 月 9 日
Yes, this is what was suggested yesterday.
If the length of M is a multiple of 2, an equivalent code is:
v = (M(1:2:end) + M(2:2:end)) * 0.5;
t = t(1:2:end)
MakM
MakM 2022 年 2 月 9 日
Thank you Jan, Kindly paste your answer, so I can accept :)

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

採用された回答

Jan
Jan 2022 年 2 月 9 日
編集済み: Jan 2022 年 2 月 9 日
A simple average over 2 elements (length of M can be even or odd):
Len = numel(M);
v = (M(1:2:Len - rem(Len, 2)) + M(2:2:Len)) * 0.5;
t = t(1:2:end)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by