summation of array elements
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Terry McGinnis
 il 22 Giu 2015
  
    
    
    
    
    Modificato: Azzi Abdelmalek
      
      
 il 22 Giu 2015
            I have an array of say 5 elements and I want to run a loop and find the cumulative sum till the ith iteration eg.
array if f=[1 2 3 4 5]
so in the first iteration sum should be 1,in the 2nd it should be 3,in the third it should be 6 and so on...
what is the most efficient way to do this?
thanks in advance:]
0 Commenti
Risposta accettata
  Azzi Abdelmalek
      
      
 il 22 Giu 2015
        
      Modificato: Azzi Abdelmalek
      
      
 il 22 Giu 2015
  
      f=[1 2 3 4 5];
out=cumsum(f)
4 Commenti
  Guillaume
      
      
 il 22 Giu 2015
				or just iterate over the cumsum
f = [1 2 3 4 5]
for s = cumsum(f)
  %do something with s
end
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements 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!

