How do I automate adding columns together
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marissa Holden
le 9 Mai 2022
Modifié(e) : Dyuman Joshi
le 9 Mai 2022
I have a large data matrix (513*63)
I want to add each column together and then divide them to create a single vector.
At the moment all I can think of is
matrix = 513x63
column_one= [matrix(:,1)]
column_two= [matrix(:,2)]
column_three= [matrix(:,3)]
vector_variable = column_one + column_two + column_three/3
Is there a way that I can automate this process to loop over 63 columns?
1 commentaire
Walter Roberson
le 9 Mai 2022
Are you wanting to take the mean of the 63 sums?
Are you wanting to take 11 groups, 1:3, 4:6 and so on?
Are you wanting to take a moving mean of adjacent groups of 3, 1:3, 2:4, 3:5 and so on?
Réponse acceptée
Dyuman Joshi
le 9 Mai 2022
Modifié(e) : Dyuman Joshi
le 9 Mai 2022
An example based on what you wrote
y = randi(100,513,63);
z=[];
for i=1:3:63 %groups of 3 as you mentioned
z=[z sum(y(:,i:i+2),2)/3];
end
z
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!