function indexing
%function indexing
%
% This function shows how MATLAB handles incorrect indexing into
% arrays.
%
% Author: Lina Arbach <lina@lina-arbach.com>

% First create a row vector for explanation
vec1 = [1 2 3]

% This is a syntax error. 
% Use parenthesis (), not brackets []
% Comment this line to continue
vec1[1]

% This is an index error. The first index in MATLAB is 1, not 0
% Comment this line to continue
vec1(0)

% This is the correct form
vec1(1)

% Now show how 2 dimensional indexing works
% The elipsis (...) allows you to wrap lines
array = ...
    [1 2 3; ...
     4 5 6; ...
     7 8 9]

% That was equivalent to
% array = [1 2 3; 4 5 6; 7 8 9];

% Now the first row, second column should be 2, not 4
array(1, 2)
