sumc = @(m) [m; sum(m)];sumr = @(m) [m sum(m,2)];f = @(m) sumc(sumr(m));f([1:3; 4:6]) g = @(m) [m sum(m,2); sum(m) sum(m(:))];g([1:3; 4:6])
Standard input is empty
ans = 1 2 3 6 4 5 6 15 5 7 9 21 ans = 1 2 3 6 4 5 6 15 5 7 9 21
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!