Next: 1.4.0.1 Built-in variables
Up: 1. Getting started with
Previous: 1.3 Matlab as a
  Contents
Variables are a place to store values and results. For example, try this:
x = 2
x
What happened? When you typed x=2, MATLAB assigned the value of 2
to the variable x. When you typed x, MATLAB returned the
value of x. Try typing y instead. MATLAB complains
because the variable y has not yet been assigned a value and is
therefore undefined.
It is important (even if you don't understand yet why) NOT to read
x=2 as ``x equals two.'' That is not what it means! To
MATLAB, the statement x=2 means ``assign the variable x the
value of 2.'' The = symbol is an assignment operator. (The
``equality'' operator is ==. Incidentally, this is generally true
for all programming languages, not just MATLAB.)
The = assignment operator works not only for values but also for
expressions. Try,
y = 2+2
z = y*3
a = z+y
b = a+z-y
Make sure you understand why
MATLAB gives the answers it does. Notice that the quantity being assigned
to a variable can even be another variable itself or an expression
including other variables.
Subsections
Next: 1.4.0.1 Built-in variables
Up: 1. Getting started with
Previous: 1.3 Matlab as a
  Contents
Gus Hart
2005-01-28