MATLAB: How to get the sum of rows and columns of a table and add them to the table

MATLABtable

I want to get the totals of each row and column from a table with values inserted by a user
This is my script so far:
row = input('Enter number of rows: ');
col = input('Enter number of columns: ');
for i = 1:row
for j = 1:col
str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': '];
A(i,j) = input(str);
end
end
A;
See the images for how I want it to look compared to how it looks now

Best Answer

After you get the row and col values from the user, pre-allocate it by,
A = zeros(row+1,col+1);
I say "+1" because that'S where I want to store the sum. Now get the values from user as in the for loop, then to caluclate sum of all rows,
A(end,1:col) = sum(A(1:row,1:col),1); %last element will be 0
to sum all columns
A(1:row,end) = sum(A(1:row,1:col),2); %again, last element will be 0
final result will be like, (for a 3x3 input)
0.8673 0.8289 0.2804 1.9766
0.7212 0.7730 0.7949 2.2891
0.1438 0.3716 0.2151 0.7304
1.7322 1.9735 1.2904 0