1 / 8

Introduction to Programming in MATLAB

Introduction to Programming in MATLAB. Intro. MATLAB Peer Instruction Lecture Slides by  Dr. Cynthia Lee, UCSD  is licensed under a  Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License . Based on a work at  www.peerinstruction4cs.org. LOOPS: Examples.

deacon
Download Presentation

Introduction to Programming in MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.Based on a work at www.peerinstruction4cs.org.

  2. LOOPS: Examples

  3. Fill in the blank in the following code to create an infinite loop. Do no not add or change code except adding one line of code on the blank line. • counter = inf; % MATLAB built-in value “inf” • counter = 1; • counter = counter – 1; • Other/none/more than one

  4. Write a loop that counts how many pure blue ([0 255 0]) pixels are in an image. function [blues] = CountBluePixels(im) for row = for col = pix = im(row,col,:); end end end

  5. How many times is “CSE 7” printed when this code runs? • 2 times • 3 times • 5 times • 12 times • Other/none/more than one

  6. What is the value of alpha after this code runs? • 4 • 5 • 7 • 10 • Other/none/more than one

  7. Write a loop that finds the average amount of red in an image. function [ave] = AverageRed(im) for row = for col = red = im(row,col,1); end end end

  8. How many times does ‘hi’ print? row = 1; while row <= 2 for col = 1:10 display(‘hi’) row = row + 1; end row = row + 1; end • 0 • 2 • 10 • 20 • Keeps printing ‘hi’ forever in an infinite loop

More Related