Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 23 de Feb. de 2020
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 comentarios
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 23 de Feb. de 2020
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 );

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by