ANSWERS TO EXERCISE 2:

 

 

1.     row = (1:20)';

table = [row, row.^2, 2.^row]

 

2.     b = [0, 1; 1, 0];

row = [b, b, b, b]

chess = [row; row; row; row]

 

3.   col1 = randperm(15); col1 (6:end) =[];

col2 = randperm(15) + 15;    col2 (6:end) =[];

col3 = randperm(15) + 30;    col3 (6:end) =[];

col4 = randperm(15) + 45;    col4 (6:end) =[];

col5 = randperm(15) + 60;    col5 (6:end) =[];

bingocard = [col1', col2', col3', col4', col5'];

 

Notice the repetition of code. The same task can be accomplished using a FOR LOOP:

 

bingocard = zeros(5);

for k = 1:5

                        col = randperm(15) + (k-1)*15;

            col (6:end) =[];

                        bingocard(:,k) = col';

end

bingocard