Average every 3 Rows in Single Column in Table
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Spencer Ferris
le 21 Fév 2021
Commenté : KALYAN ACHARJYA
le 22 Fév 2021
I have a column in a table where I want to make a new column of data based on the average of every 3 values in that column. Tried some other solutions here but none seemed to work for me.
0 commentaires
Réponse acceptée
KALYAN ACHARJYA
le 21 Fév 2021
Modifié(e) : KALYAN ACHARJYA
le 21 Fév 2021
Lets consider one Table Example
LastName = {'A';'B';'C';'D';'E';'F'};
Age = [38;43;38;40;49;50];
T = table(LastName,Age);
Table
T =
6×2 table
LastName Age
_______ ___
{'A'} 38
{'B'} 43
{'C'} 38
{'D'} 40
{'E'} 49
{'F'} 50
Access the particular column, let's say age data
age_col=T.Age
Result:
>> age_col=T.Age
age_col =
38
43
38
40
49
50
Now Average the 3 consecutive rows of the column vector. Easiest way reshape the data then mean
data1=reshape(age_col,[3,2])
%........................^ you can generelize this sizes
Next find the mean and transpose
av_result=mean(data1)'
Result:
av_result =
39.6667
46.3333
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!