Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Cumulative sum
Posted:
Jan 28, 2013 6:53 AM
|
|
for i = 1 : 5 if issorted(flipud(hewson([1:2],i))) %assumes that you only care about top 2 elements hewson(:,end+1) = cumsum(hewson(:,i),1) end end
hewson =
1 5 8 4 7 8 3 6 4 7 9 12 3 6 7 9 5 19 2 5 6 7 5 25
Barry
"sam" wrote in message <ke5kpo$gjt$1@newscl01ah.mathworks.com>... > I am new to Matlab and trying to create a a fairly simple matrix. one of my columns i want to be the cumualtive sum of another column. For example the below matrix, i want the next column (6) to be the cumulative sum of column 3 as it decends. so the first number will be 8 then the second number will be (8+4) 12 then the third will be (8+4+7) 19 and so on. > > 1 5 8 4 7 > 3 6 4 7 9 > 3 6 7 9 5 > 2 5 6 7 5 > > i havetried various ways such as the one below but with no success, can anyone please tell me where i am going wrong? > hewson is the name of my matrices > > for r = 1:20 > for c=6 > hewson (r,c) = cumsum(r,3); > end > end > > Many Thanks > sam
|
|
|
|