Take the average of predefined consecutive values in a matrix array
5 ビュー (過去 30 日間)
古いコメントを表示
Jorge Luis Paredes Estacio
2023 年 7 月 18 日
コメント済み: Jorge Luis Paredes Estacio
2023 年 7 月 18 日
Hello, I would like to calculate the average of consecutive values from a predifined number of elements from a Nx1 matrix, where N is the number of rows. For example, let's say I have a matrix with the following form (24x1):
A[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24]
I want to obtain the average for every 5 elements,
B=[(1+2+3+4+5)/5; (2+3+4+5+6)/5; (3+4+5+6+7)/5;...........(20+21+22+23+24)/5]
I am chosing every 5 elements to simplify the example. But, this number can be higher than 20.
I would appreciate the help.
0 件のコメント
採用された回答
Dyuman Joshi
2023 年 7 月 18 日
A = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24];
%Moving mean with 5 element windows, discarding the end points
B = movmean(A,5,'Endpoints','discard')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!