1
MatLab Basics
MatLab was designed as a Matrix Laboratory, so all operations are assumed to be done on
matrices unless you specifically state otherwise. (In this context, numbers (scalars) are simply
regarded as matrices with one row and one column.) A matrix is an array of numbers arranged
in rows and columns. You will study these in detail in a Linear Algebra course (Math 1114).
Since we will be using MatLab here for Calculus of real numbers, not matrices, some of the
arithmetic operators discussed below will be different than the standard ones that you would
expect. Press “return” after each MatLab statement as you work through the examples below.
Most of the time, the corresponding output from MatLab is also given so that you may check
your typing.
An “equals” sign is used to make an assignment. For example, type the following after the “>>”
prompt in your command window:
x=2
Now, press “return” to see what Matlab has stored as your variable x.
You should see:
»x = 2
x =
2
If you just type 2, then MatLab will store it in the default variable, “ans”.
»2
ans =
2
Right now, you have assigned x = (a list consisting of just one number, 2)
You can also give a variable such as x a range of values (i.e., define it to be an array) by using a
colon, “:”. For example, to let “x” take on all of the positive integers from 2 to 4, type:
»x=2:4
x = 2 3 4
The semicolon, ;, suppresses output. Type “x = 2:4;” and see what happens. You can also enter
the array as x = [ 2, 3, 4] or x = [ 2 3 4]. Spaces separate the numbers in the last entry.