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
Post a Comment