how to keep first 3 datas and obtain average, then skip or ignore the next 3 data and keep next 3 datas again....??

1 回表示 (過去 30 日間)
Hi all.
I have a 216 data in a one column from excel. but i want to keep first 3 datas and obtain average, then skip or ignore the next 3 data and keep next 3 datas again until finish 1:216, someone how to do that?

採用された回答

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 2 月 23 日
An efficient way to do this is to create all the index that are going to belong to the average and then do it in a vectorized way. In your case, you can define each value belonging to the average with intervals of 6 values, an example can be done like this:
N = 15;
A = 1:N; % Simple vector to verify result, substitute by your A with N = 216
idx1 = 1:6:N;
idx2 = 2:6:N;
idx3 = 3:6:N;
Average = mean( [A(idx1);A(idx2);A(idx3)] )'
Average =
2
8
14
  3 件のコメント
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 2 月 23 日
You use the same logic as my answer, in your exact case you can write
v1=dat(5:end,9);
N = size(v1,1);
idx1 = 1:6:N;
idx2 = 2:6:N;
idx3 = 3:6:N;
filteredv1=[v1(idx1),v1(idx2),v1(idx3)]';
filteredv1 = filteredv1(1:end)';
Averagev1 = mean( [v1(idx1),v1(idx2),v1(idx3)],2 );

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by