GEOSC 444
Matlab Application for Geoscience

Lesson 1: A big difference between MATLAB and a spreadsheet program

PrintPrint

Reassigning a variable to a new value does not automatically re-perform any past calculations involving that variable. For example, see the following set of commands:

>> a=3;b=4;
>> c=a+b
c =
     7
>> a=5;
>> c
c =
     7

In this series of operations, I first set a equal to 3 and b equal to 4. I set c equal to the sum of a and b. MATLAB tells me c is 7. So far, so good. Then I set a equal to 5. In a spreadsheet program, c would be recalculated to take into account the new value of a but MATLAB doesn't do that, which I can verify by typing c to find out its value. MATLAB tells me c is still 7.

Check yourself!

How about this one?