% Example 9-6: Building a matrix n = input('Enter the number of rows: '); m = input('Enter the number of columns: '); A = []; for r = 1:n for c = 1:m if r==1 % Assign first row with column number A(r,c) = c; elseif c==1 % Assign first column with row number A(r,c) = r; else % Fill in other elements with sum of % element above and to the left A(r,c) = A(r-1,c) + A(r, c-1); end end end A