% test_mtx.m  many types of matrix
function test_mtx()
  diary('test_mtx_m.out')
  A1 = [ 1 2 3 4 ; 5 6 7 8 ; 9 10 11 12 ; 13 14 15 16 ] % row major
  prt_mtx('A1', A1);

  A2 = [ 1,2,3,4 ; 5,6,7,8 ; 9,10,11,12 ; 13,14,15,16 ] % same
  prt_mtx('A2', A2);

  A3 = [[1 2 3 4]',[5 6 7 8]',[9 10 11 12]',[13 14 15 16]'] % column major
  prt_mtx('A3', A3);    % A3 is A1 transpose    A3 = A1'

  A4 = zeros(4,4) % initialize each element of matrix
  A4(1,1) =  1; A4(1,2) =  2; A4(1,3) =  3; A4(1,4) =  4;
  A4(2,1) =  5; A4(2,2) =  6; A4(2,3) =  7; A4(2,4) =  8;
  A4(3,1) =  9; A4(3,2) = 10; A4(3,3) = 11; A4(3,4) = 12;
  A4(4,1) = 13; A4(4,2) = 14; A4(4,3) = 14; A4(4,4) = 16;
  disp(A4)
  prt_mtx('A4', A4);

  k = 1;
  n = 4
  for i=1:n
    for j=1:n
      A5((i-1)*n+j) = k; % row major
      A6(i+(j-1)*n) = k; % column major
      k = k+1;
    end % j
  end % i
  disp(A5)
  prt_mtx('A5', A5);
  disp(A6)
  prt_mtx('A6', A6);

  function prt_mtx(name, M) % very flexible about matrix M
    pstr=[name,' (1,1) and (1,2)'];
    disp(pstr)
    disp(M(1,1))
    disp(M(1,2))
  end % prt_mtx
end % test_mtx
