Please check the following expression in MATLAB. the second argument of cumsum is not translated correctly and tril is not translated to trimatl. si = tril(reshape(cumsum(reshape(C(2:end,:)*DT,n,n-1),2),n-1,n)); C: nxm DT: mxn Thanks