フィルターのクリア

Moving sum of 4 subsequent observatins

4 ビュー (過去 30 日間)
Joanna Przeworska
Joanna Przeworska 2021 年 3 月 24 日
コメント済み: Joanna Przeworska 2021 年 3 月 25 日
How can I get the moving sum of 4 subsequent observations out of variable 'var'? In specific, I would like the new variable to be constructed as follows:
(81,0970 + 85,2039 + 90,0506 + 89,0082) = ...
(85,2039 + 90,0506 + 89,0082 + 100,3168) = ...
(90,0506 + 89,0082 + 100,3168 + 105,4897) = ...
...

採用された回答

Steven Lord
Steven Lord 2021 年 3 月 24 日
Use the movsum function.
  1 件のコメント
Joanna Przeworska
Joanna Przeworska 2021 年 3 月 25 日
Dear Steven,
movsum(A,[3 0]) solves my problem. Thank you.
Best regards,
JP

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

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 3 月 24 日
hello
see example below (run it with 4 and not 5 samples averaging) :
% dummy data
data = rand(320,15);
buffer = 5; % nb of samples for averaging
% zero overlap mean averaging
[m,n] = size(data)
for ci=1:fix(length(data)/ buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer,length(data));
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
avg_data(ci,:) =mean(data(start_index:stop_index,:)); %
end
figure(1),
plot(time_index,avg_data);
  2 件のコメント
Joanna Przeworska
Joanna Przeworska 2021 年 3 月 25 日
Dear Mathieu,
Thank you for your suggestion, however, to be honest, I thought there could be more simplest way to solve my problem. If am not able to find any other, I will use our idea.
Kind regards, JP
Mathieu NOE
Mathieu NOE 2021 年 3 月 25 日
hello Joanna
it's coming from long time ago when I rote most of the functions I still use today, now , as mentionned by Steven Lord below, you can do it in one line with movsum;
but basically that movsum function implements the code I show you

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by