Introduction to Programming in MATLAB

# Introduction to Programming in MATLAB

## Introduction to Programming in MATLAB

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

2. Relational Operators

3. Relational Operators • 4 < 5 true (1) • 4 <= 5 true (1) • 4 == 5 false (0) • 4 ~= 5 • 4 > 5 false (0) • 4 >= 4 • ‘A’ < ‘B’ (a) true (1) (b) false (0) (c) other/error (a) true (1) (b) false (0) (c) other/error (a) true (1) (b) false (0) (c) other/error

4. Why would we want to test “<“ between a number and a matrix? >> im = imread(‘rainbow.jpg’); >> g = im(:,:,2); >> result = g > 200; • What type of variable will result be after the assignment? What does this code do, conceptually? • Increases the amount of green in the image • Identifies pixels with high green value • Removes green layer from the image • None/more than one/MATLAB error

5. A new data type for variables!

6. LOGICAL Operators

7. Why would we want to test “<“ between a number and a matrix? >> im = imread(‘rainbow.jpg’); >> result = im(:,:,1) > 200 & im(:,:,2) > 200 & im(:,:,3) > 200; • First, take each part by itself and figure out what it does; then combine the parts. What does this code do, conceptually? • Identifies pixels that have high red, or high blue, or high green value(s) • Identifies pixels that are close to black • Identifies pixels that are close to white • Error

8. Can you write code for the other answer choices? >> im = imread(‘rainbow.jpg’); >> result = im(:,:,1) > 200 & im(:,:,2) > 200 & im(:,:,3) > 200; • Identifies pixels that have high red, or high blue, or high green value(s) • Identifies pixels that are close to black

9. “Green screen” special effects • Actors or other objects are filmed in front of a screen with a very specific shade of green • Later, a computer program checks the color of each pixel of the movie • Pixels matching that specific shade of green are replaced with pixels from another image/movie • Pixels not matching that specific shade of green are left alone

10. “Green screen” special effects • Actors can wear green and be invisible in the final movie • The two men on the left are moving a puppet • The man on the right, if he doesn’t put his green shirt back on, will appear to be a floating torso