How do I automate adding columns together
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Marissa Holden
il 9 Mag 2022
Modificato: Dyuman Joshi
il 9 Mag 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 Commento
Walter Roberson
il 9 Mag 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?
Risposta accettata
Dyuman Joshi
il 9 Mag 2022
Modificato: Dyuman Joshi
il 9 Mag 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!