help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sum Row In Matrix


From: Ian McCallion
Subject: Re: Sum Row In Matrix
Date: Thu, 9 May 2019 15:12:30 +0200

Very weird code for what is effectively a cumulative sum of the rows:

dailyprofit = [1,2,3;4,5,6];

A=dailyprofit;
for i=1:columns(dailyprofit)
for ii=1:rows(dailyprofit)
 if i>1
     A(ii,i)=A(ii,i-1)+dailyprofit(ii,i);
   endif  
endfor  
endfor

A
B=cumsum(dailyprofit,2)

Cheers... Ian

On Thu, 9 May 2019 at 14:46, turbofib via Help-octave <address@hidden> wrote:
i semplity it :

A=dailyprofit;

for i=1:columns(dailyprofit)
for ii=1:rows(dailyprofit)
   if i>1
     A(ii,i)=A(ii,i-1)+dailyprofit(ii,i);
   endif
endfor 
endfor



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]