for loop to sum values
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (3)
Jan
el 15 de Oct. de 2022
Editada: Jan
el 15 de Oct. de 2022
what about the answer given to your similar question: https://www.mathworks.com/matlabcentral/answers/1826808-sum-of-values-in-matrix-with-a-loop#answer_1075888
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
0 comentarios
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
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!