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 天)
显示 更早的评论
Eder Hernandez Martinez
2020-2-23
评论: Eder Hernandez Martinez
2020-2-23
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 个评论
采纳的回答
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
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 Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!