Introduction to Programming in MATLAB

Slides:



Advertisements
Similar presentations
Chapter 4 Ch 1 – Introduction to Computers and Java Flow of Control Loops 1.
Advertisements

CSE 20 – Discrete Mathematics Dr. Cynthia Bailey Lee Dr. Shachar Lovett Peer Instruction in Discrete Mathematics by Cynthia Leeis licensed under a Creative.
Virtual Memory Really this is in OS – but We need to see how the OS will interact with the HW Peer Instruction Lecture Materials for Computer Architecture.
Introducing DFA Formal Description Using Peer Instruction Cynthia Bailey Lee UCSD 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia.
Pipeline Summary Try to put everything together for pipelines Before going onto caches. Peer Instruction Lecture Materials for Computer Architecture by.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
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.
THE PUMPING LEMMA PROVING A LANGUAGE IS NOT REGULAR Dr. Cynthia Lee - UCSD - Spring 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia.
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.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
Introduction Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
MATLAB Programming Session
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
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.
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.
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.
Tutorial: Reduction from A TM Proofs Dr. Cynthia Lee CSE 105, UCSD Spring 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee,
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.
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.
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.
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.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
BEGINNER PROGRAMMING LESSON
Percentage Yields C2.3.5.
Repeating Code Multiple Times
Programming Abstractions
Basic cookery terms are identified correctly
CSE 20 – Discrete Mathematics
By Sanjay and Arvind Seshan
Controlling execution - iteration
A Lecture for the c++ Course
Programming Abstractions
Introduction to Programming in MATLAB
Chapter 5: Loops and Files.
Algorithm Analysis CSE 2011 Winter September 2018.
Lecture 07 More Repetition Richard Gesick.
Sampling Distributions
Parallel Beam Synchronization
Determining Sample Size
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Iteration with While You can say that again.
Intro to Statistical Inference
By Sanjay and Arvind Seshan
Beginner Programming Lesson
CISC181 Introduction to Computer Science Dr
Student’s t-Distribution
Gyro Turns © 2015 EV3Lessons.com, Last edit 12/19/2015.
Parallel Beam Synchronization
Michael L. Nelson CS 495/595 Old Dominion University
Downloading & Uploading Files
Section 1.5—Significant Digits
By Sanjay and Arvind Seshan
Repeating Actions (Loops)
By Sanjay and Arvind Seshan
BEGINNER PROGRAMMING LESSONS
Downloading & Uploading Files

BEGINNER PROGRAMMING LESSONS
By Sanjay and Arvind Seshan
Designing a Pipelined CPU
Photo by fortinbras - Creative Commons Attribution-NonCommercial-ShareAlike License Created with Haiku Deck.
Loops.
Photo by Sean Barnard - Creative Commons Attribution-NonCommercial License Created with Haiku Deck.
Introduction to Programming in MATLAB
Do you trust the 8 Ball? The 8 Ball always knows..
Introduction to Programming in MATLAB
Access Control Slide Set #4 Textbook Chapter 4 Clicker Questions
The while Looping Structure
Presentation transcript:

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.

for loops Think about possible drawbacks of using for loops for an action that you want to repeat many, many times is. For example, let’s say you want to add up all the numbers from 1 to 100,000 and you write this loop to do it: sum = 0; for num = 1:100000 sum = sum + num; end What is one drawback of doing the calculation this way? It might take so long to calculate that it will forget the sum and come up with the wrong answer MATLAB actually makes a vector with size 100000 to hold all the values of num that will be used, and this takes up a huge amount of space in the computer’s memory It might take so long to calculate that it will never finish Other B Is not really possible Correct Not a problem in this case, though when we get to while loops we will experience code that never finishes (infinite loop)

for loops Is this code legal/valid? What does it do? im = imread(‘blacklab.jpg’); for row = [2 66 101 11 43 35 85 170] im(row,:,:) = 0; end Is this code legal/valid? What does it do? See next slide for answer.

for loops

for loops im = imread(‘blacklab.jpg’); for row = 1:2:size(im,1) im(row,:,:) = 0; end for row = [1 3 5 7 9…keep going…357]

for loops vs. while loops for row = 1:2:end im(row,:,:) = 255; end row = 1; while row <= end im(row,:,:) = 255; row = row + 2; end A good slide for students to bookmark and refer to often. % vector (non-loop) % not always possible to vectorize your loop, % but *very* preferable you can! im(1:2:end,:,:) = 255;