how to keep first 3 datas and obtain average, then skip or ignore the next 3 data and keep next 3 datas again....??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Eder Hernandez Martinez
am 23 Feb. 2020
Kommentiert: Eder Hernandez Martinez
am 23 Feb. 2020
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?
0 Kommentare
Akzeptierte Antwort
Thiago Henrique Gomes Lobato
am 23 Feb. 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 Kommentare
Thiago Henrique Gomes Lobato
am 23 Feb. 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 );
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!