Calculate average of specific values in one table column
Mostra commenti meno recenti
Say I have this table, in which the last column is a calculation from the previous three.
I want to find the average of the last column in the table, but only within certain groups. So I want to find the average value of the first four values, then the next four, then the next four, etc. What would be the most sophisticated way to do this? And is there also a way to put those values into one neat place?
I really appreciate the help, I am new to MatLab and it is still a bit confusing for me. Thank you!
8 1e-05 0.0001 8e+09
9 1e-05 0.0001 9e+09
1 1e-05 0.0001 1e+09
10 1e-05 0.0001 1e+10
6 1e-05 0.0001 6e+09
1 1e-05 0.0001 1e+09
3 1e-05 0.0001 3e+09
6 1e-05 0.0001 6e+09
10 1e-05 0.0001 1e+10
10 1e-05 0.0001 1e+10
1 1e-05 0.0001 1e+09
10 1e-05 0.0001 1e+10
10 1e-05 0.0001 1e+10
5 1e-05 0.0001 5e+09
8 1e-05 0.0001 8e+09
1 1e-05 0.0001 1e+09
Risposta accettata
Più risposte (1)
infinity
il 19 Giu 2019
Hello,
Here is one solution that you can use
a = ...
[8 1e-05 0.0001 8e+09
9 1e-05 0.0001 9e+09
1 1e-05 0.0001 1e+09
10 1e-05 0.0001 1e+10
6 1e-05 0.0001 6e+09
1 1e-05 0.0001 1e+09
3 1e-05 0.0001 3e+09
6 1e-05 0.0001 6e+09
10 1e-05 0.0001 1e+10
10 1e-05 0.0001 1e+10
1 1e-05 0.0001 1e+09
10 1e-05 0.0001 1e+10
10 1e-05 0.0001 1e+10
5 1e-05 0.0001 5e+09
8 1e-05 0.0001 8e+09
1 1e-05 0.0001 1e+09];
b = zeros(4,1);
for i = 1:4
b(i) = mean(a((i-1)*4+1:i*4,4));
end
for your data, I save it to a variable "a". Then, you can create a variable "b" that will be used to save the average that you want to compute. Next, an easy way that you can implement the "for" loop to compute the average with specific group that you want.
Best regards,
Trung
1 Commento
Jenniluyn Nguyen
il 20 Giu 2019
Categorie
Scopri di più su Matrices and Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!