Search Program on this blog

Friday 6 November 2015

Write a function called mtable that returns mt an n-­‐by-­‐m matrix corresponding to the multiplication table (n is the first and m is the second input argument). That is, the element of mt at row ii and column jj equals to ii*jj. The function also has a second output, s, a scalar that equals the sum of all the elements of mt.

function [mt s] = mtable(n,m)
for i=1:n
    for j=1:m
        mt(i,j) = i*j;
    end
end
s = sum(sum(mt));

No comments:

Post a Comment