for loop to sum values

2 visualizaciones (últimos 30 días)
zhi cheng
zhi cheng el 15 de Oct. de 2022
Respondida: Abdullah Emir el 15 de Abr. de 2024
I need to sum the value of
row column + row column + ... + row column
1 6,7,8 145 6,7,8 ... 6,7,8
2 6,7,8 146 6,7,8 ... 6,7,8
3 6,7,8 147 6,7,8 ... 6,7,8
... 6,7,8 ... 6,7,8 ... 6,7,8
144 6,7,8 288 6,7,8 52560 6,7,8
X=zeros(1,3);
x = 365
for i = 1:length(outDates(:,5))
avgspeeds = zeros(1,3);
for j = 1:3
sum1 = outDates(i,5+j) + outDates(i+n,5+j)
end
end
  2 comentarios
KSSV
KSSV el 15 de Oct. de 2022
Read about sum
zhi cheng
zhi cheng el 15 de Oct. de 2022
thank you for your reply, but I still dont get it from the info in helpcenter talk about how to sum the whole row/column
but I need to sum specific rows and columns eg: row1,row145,row289,row433.... there is a gap of 144rows between them and sum
row2,row146,row290,row434
row3,row147,row291,row435
so on until row 144
and the columns from 6-8

Iniciar sesión para comentar.

Respuestas (3)

Jan
Jan el 15 de Oct. de 2022
Editada: Jan el 15 de Oct. de 2022
No loop needed:
X = reshape(outDates(:, 6:8), 144, [], 3); % Reshape to 3D array
Y = squeeze(sum(X, 2) / size(X, 2)); % Mean over 2nd dimension

Torsten
Torsten el 15 de Oct. de 2022
outDates = rand(52560,9);
sums = zeros(144,1);
for i=1:144
sums(i) = sum(outDates(i+(0:364)*144,6)) + sum(outDates(i+(0:364)*144,7)) + sum(outDates(i+(0:364)*144,8));
end
sums
sums = 144×1
547.5205 549.0608 553.0107 551.1408 534.0514 551.2122 553.6387 539.5439 546.9188 536.9660

Abdullah Emir
Abdullah Emir el 15 de Abr. de 2024
thank you

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by