write a function called timestable that outputs a times table up to the size requested, given by a positive integer sizeoftable. the top row and left column have integers from 1 to the desired size. in matlab

Here is an implementation of the timestable function in MATLAB using nested loops:

main.m
function t = timestable(sizeoftable)
%TIMESTABLE Generate a times table up to a given size.
%   T = TIMESTABLE(SIZEOFTABLE) generates a times table up to SIZEOFTABLE. The
%   first row and first column contain integers from 1 to SIZEOFTABLE.

% Initialize the output table
t = zeros(sizeoftable);

% Fill the first row and first column with integers
for i = 1:sizeoftable
    t(1, i) = i;
    t(i, 1) = i;
end

% Fill the rest of the table with products
for i = 2:sizeoftable
    for j = 2:sizeoftable
        t(i, j) = t(i, 1) * t(1, j);
    end
end

% Display the table
disp(t);
end
585 chars
25 lines

This function takes a positive integer sizeoftable as input, and generates a times table up to the given size. The first row and first column contain integers from 1 to sizeoftable, and the rest of the table contains products of those integers. It uses nested loops to iterate over the rows and columns of the output table, and computes the product of the corresponding row and column headers. Finally, it displays the resulting times table using the disp function.

gistlibby LogSnag