フィルターのクリア

How to find sum of previous 5 numbers in a column..

2 ビュー (過去 30 日間)
Dhanalakshmi M
Dhanalakshmi M 2022 年 7 月 28 日
コメント済み: Dhanalakshmi M 2022 年 7 月 28 日
I have a column with certain readings. I want to find the sum of previous 5 numbers for the entire column. I am not familiar with for statement in matlab. Can anyone help. I am giving below the data in column 1 and the result needed in colmn 2. Thanks in Advance.
Data Sum of previous 5 numbers
56
45
56
678
678 1513
568 2025
2 1982
3 1929
4 1255
5 582
6 20
7 25
23 45
35 76
45 116
56 166
63 222
57 256
56 277
78 310
Regards.

採用された回答

Chunru
Chunru 2022 年 7 月 28 日
x = [56 45 56 678 678 568 2 3 4 5];
y = filter(ones(5,1), 1, x)
y = 1×10
56 101 157 835 1513 2025 1982 1929 1255 582
y1 = y(5:end)
y1 = 1×6
1513 2025 1982 1929 1255 582
  1 件のコメント
Dhanalakshmi M
Dhanalakshmi M 2022 年 7 月 28 日
Thanks a lot, it works.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by