Entering Matrices with MATLAB

Entering Matrices with MATLAB

For a tutorial on MATLAB that is calculus specific you can point your browser at http://www.math.csi.cuny.edu/MATLAB/tutorial/.

Creating Matrices To create matrices you designate to MATLAB that you want a matrix with the square brackets:

,
. How to access numbers in a MATRIX

Here is a side diversion:

Generating numbers

An important command to generate numbers in a systematic way is to use the colon operator. its syntax is

>> a:b                          % from a to b by 1's
>> a:h:b                        % from a to b by steps of size 'h'

for example the commands below give the output indicated

>> 1:3                          % same as [1 2 3] 
>> 1:2:9                        % gives [1 3 5 7 9]

More on slices

We use these to extract parts of matrices.

For example the ones above could be written

>> A(1:2,3)                   % A(1,3) and A(2,3)
ans =
  7
  8
>> A(2,1:2)                   % A(2,1) and A(2 2)
ans =
   4  -7

Finally, there is a shortcut when you want the entire row or column. Just use a semicolon ``:''

>> A(:,2)
ans =
   6
  -7
>> A(2,:)
ans =
   4  -7   8


File translated from TEX by TTH, version 1.1.