% Accessing elements of multidimension arrays a = 1:12; % define a 1D array A = reshape(a,4,3) % reshape turns the elements of 'a' into a 4x3 array % we didn't have to initialize A this way, it's just % convenient A(2,3); % gives 10 (the 6th element of 'A') A(3:4,2:3) % gives a 2x2 array using the rows 3 & 4 and columns 2 & 3 B = A(:,3:-1:1) % Tricky! How does this work? B(3,1) = pi % Replace just a single element with piMATLAB can handle arrays with any number of dimensions. We will rarely find a use for arrays with more than 3 dimensions. Two- and one-dimensional arrays (matrices and vectors) are at the heart of computational physics, so we'll use these the most.

Gus Hart 2005-01-28