How to calculate a cumulative sum in a loop?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sandy
el 20 de Nov. de 2013
Comentada: Walter Roberson
el 21 de Nov. de 2013
I have a loop that looks like this:
for a = 1: 9
for b = 1 : 1000
for c = 1 : 1000
image = myimage_bands(b, c, a);
new_image = image * 5;
end
end
end
I am trying to find the cumulative sum of my variable 'new_image', as it goes through the loop. I've tried cumsum, but it doesn't work.
Any ideas are appreciated. Thanks!
1 comentario
Azzi Abdelmalek
el 20 de Nov. de 2013
Editada: Azzi Abdelmalek
el 20 de Nov. de 2013
There is no cumulative sum in your code, can you explain what you want?
Respuesta aceptada
Walter Roberson
el 21 de Nov. de 2013
Before the loop,
image_sum = [];
inside the loop after you have calculated new_image,
if isempty(image_sum)
image_sum = new_image;
else
image_sum(end+1) = image_sum(end) + new_image;
end
2 comentarios
Walter Roberson
el 21 de Nov. de 2013
image_sum(:,:,end+1) = image_sum(:,:,end) + new_image;
Más respuestas (0)
Ver también
Categorías
Más información sobre Design and Simulate SerDes Systems 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!