How do I automate adding columns together

3 visualizzazioni (ultimi 30 giorni)
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
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?

Accedi per commentare.

Risposta accettata

Dyuman Joshi
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
z = 513×21
52.6667 65.6667 74.0000 72.6667 30.0000 56.6667 42.0000 81.3333 27.3333 65.0000 51.6667 23.6667 37.6667 84.0000 27.6667 54.3333 82.6667 57.0000 54.6667 40.6667 73.3333 31.0000 23.6667 57.6667 55.0000 38.3333 52.6667 53.3333 50.0000 20.6667 54.3333 38.0000 51.0000 63.3333 52.0000 56.6667 45.3333 60.3333 28.0000 55.3333 50.6667 50.3333 42.6667 53.0000 45.0000 84.3333 26.6667 68.0000 56.0000 57.6667 47.6667 62.0000 75.3333 49.0000 34.6667 52.3333 19.3333 51.6667 49.3333 58.6667 38.3333 70.0000 43.6667 58.0000 15.0000 57.0000 47.6667 22.6667 54.3333 47.0000 34.6667 31.3333 60.3333 56.6667 77.0000 42.6667 57.0000 41.3333 59.3333 60.3333 88.3333 27.6667 21.0000 59.0000 34.6667 58.0000 53.3333 65.3333 42.0000 62.0000 63.6667 53.6667 79.3333 49.6667 26.0000 56.3333 81.3333 37.3333 13.0000 66.0000 47.3333 77.0000 72.3333 42.6667 65.3333 28.3333 65.3333 84.3333 17.0000 67.3333 64.3333 68.6667 58.6667 71.6667 43.0000 46.6667 39.3333 41.6667 37.6667 58.3333 75.6667 30.0000 59.6667 92.0000 64.6667 60.3333 68.0000 30.6667 48.0000 62.0000 78.6667 25.6667 42.3333 73.6667 39.3333 23.3333 51.0000 32.0000 40.6667 49.0000 31.3333 60.6667 59.3333 61.3333 69.6667 20.6667 57.0000 58.0000 36.3333 31.3333 75.0000 42.0000 56.3333 57.3333 56.3333 23.6667 55.6667 31.3333 39.0000 71.3333 54.6667 44.0000 68.0000 40.6667 98.0000 66.0000 57.6667 33.0000 43.6667 44.0000 59.3333 63.6667 33.6667 54.0000 10.3333 71.3333 37.6667 63.0000 70.6667 43.3333 69.6667 33.3333 53.0000 89.6667 35.0000 76.6667 54.3333 33.6667 10.6667 63.0000 90.0000 43.3333 47.0000 46.0000 64.6667 61.3333 63.3333 50.3333 43.3333 20.3333 61.0000 32.6667 74.0000 22.0000 53.6667 63.3333 77.0000 63.0000 57.6667 35.6667

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by