%% Submatrices

%% 
% Start by defining a matrix
A = [1 2 3; 4 5 6; 7 8 9; 10 11 12]

%%
% The dimensions of a matrix are given by
[r c] = size(A)

%%
% We can use this to define a new matrix
B = ones(size(A))

%%
% Note: *Indexing in MATLAB always begins with 1*
%
% To access a single element of $A$ type
A(2,3)

%%
% The second column of $A$ is given by
A(:,2)

%%
% The third row of $A$ is given by
A(3,:)

%%
% Here's a submatrix (the second and third rows of the first three
% columns)
A(2:3,1:3)

%%
% We can replace parts of a matrix
B(2,:) = [2 4 6]

%%
% or
A(1:2,1:2) = B(2:3,2:3)

%%
% We can also easily remove certain rows or columns of a matrix by
% assigning an empty vector '[]':
A([2 4],:) = []
