% multiDimensionArrays.m
% K. Ming Leung, Vov. 5, 2008

% Another way to create multidimension arrays is to use the function
% cat:

% cat(n,A,B,C,...)
% creates an array by concatenating (joining) the arrays A,B,C,...
% along the dimension n.

% Thus 
% cat(1,AA,BB) gives exactly the same result as [AA;BB]
% cat(2,AA,BB) gives exactly the same result as [AA,BB] or [AA BB]
% cat(3,AA,BB) gives a 3D array 
%              with array AA on page 1 and array BB on page 2

% For example,

AA = [ 8 2 0
       9 5 1]
BB = [  4 10 6;
       11  7 3]
CC1 = cat(1,AA,BB)
CC2 = cat(2,AA,BB)
CC3 = cat(3,AA,BB)

% The element CC3(m,n,p) is located in row m, column n, and page 3
% Thus element CC3(1,3,2) is 6:
disp(CC3(1,3,2))

% Note: the 3 different dimensions are not treated equally!!!
Res1 = CC3(1:2,2,2) % Res1 is a 2 x 1 column vector
size(Res1)
Res2 = CC3(2,1:2,2) % Res2 is a 1 x 2 row vector
size(Res2)
Res3 = CC3(2,3,1:2) % Res3 is a 1 x 1 x 2 3D array!!!
size(Res3)

MTX = Res1 * Res2   % gives a 2 x 2 matrix
s = Res2 * Res1     % gives a scalar

MTX3 = Res1 * Res3  % is illegal!!!




