Matlab - Summing from control variable in loop to end of matrix and from beginning of matrix to control variable -


as part of bigger script, have matrix 1738 * 2 (1738 rows - 2 columns) , want loop through first column (so 1738 times). dependent on iteration of loop sum the second column start value (control variable - 1) , control variable end of second column. how try start loop through first column - cog_ton 1738 x 2 matrix (the number of rows dependent on input-data).

my idea this:

for ik = cog_ton (:,1)     tonnes(ik) = sum (cog_ton (1:ik-1, 2))      tonnes2(ik) = sum(cog_ton (ik:end,2)) end 

does have idea how can implement in matlab ?

the code you've written quite similar in matlab code, minor changes, see below:

for ik = 1:size(cog_ton,1) length of column 1 in x     tonnes(ik) = sum (cog_ton (1:ik-1, 2));     tonnes2(ik) = sum(cog_ton (ik:end,2)); end 

note syntax in for-statement. ik goes 1 size(cog_ton,1), i.e. length of column 1, 1738 in example.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -