CS112: Lab 3 :: Precedence, Color and Plotting

Precedence

Here are MATLAB's rules*:
*The table below is adapted from Mastering MATLAB 7 by Hanselman and Littlefield.

Operator Precedence (from highest to lowest)

  1. Parentheses ()
  2. Transpose (.'), conjugate transpose ('), power (.^), matrix power(^)
  3. Unary plus (+), unary minus (-), negation (~)
  4. Multiplication (.*), matrix multiplication (*), right division (. /), left division (.\), matrix right division (/), matrix left division (\)
  5. Addition (+), subtraction (-), logical negation (~)
  6. Colon operator (:)
  7. Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=)
  8. Element-wise logical AND (&)
  9. Element-wise logical OR (|)

Reminders:

I. Practice with Precedence

Evaluate these expressions (by hand!):
  1. 2 ^ 2 * 4

  2. 5 + 4 - 3 ^ 2 * 1

  3. (3 > 4) | (2 < 10) == 1

  4. alex = (10 == (8 - 6 ) * 5)

  5. 1 : 4 * 2

  6. sox = 1 < 1

  7. sox = 0 < 0.5 < 1

  8. sox = 2 == 2

  9. rem(10,4)
  10. rem(10,3)
  11. rem(10,2)

II. Using color in plot

Let's extend beyond the 8 built-in MATLAB colors here.

III. Multiple plots in one figure and save/load data

An example of using subplot.
And a preview of the MATLAB commands save and load.

Prelude to Assignment 2

Assignment 2 contains two Exercises and two extended programming problems.
The Exercises are: 1) Red Sox statistics and 2) indexing with colon notation.
Click here for Assignment 2. Start with the exercises, then move to the problems.

Uploading your saved work

Use Fetch to upload your saved work.
Work-in-progress should go into your personal cs112/ folder.
The final version of your work to be turned in and graded should go into your cs112/drop/assign02 folder.