Lecture_03_horowitz

# Lecture_03_horowitz - 1 E7: INTRODUCTION TO COMPUTER E7:...

This preview shows pages 1–14. Sign up to view the full content.

E7 L3 1 E7: INTRODUCTION TO COMPUTER E7: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND PROGRAMMING FOR SCIENTISTS AND ENGINEERS ENGINEERS Lecture Outline 1. Introduction to arrays 2. One-dimensional arrays 3. Character strings

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 2 Introduction to arrays Introduction to arrays A simple array is an ordered collection of real numbers. MATLAB treats arrays very efficiently Input/output, indexing and addressing Arithmetic operations Other manipulations (e.g., sizing, reshaping, etc.) Arrays are the primary building blocks in MATLAB.
E7 L3 3 Introduction to arrays Introduction to arrays Examples 1-dimensional arrays: (1 row, 1 column) (1 row,4 columns) (3 rows, 1 [1] a = [ ] 1 5 3 2 b = - 2 1 3 c = -

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 4 Introduction to arrays Introduction to arrays Examples: 2-dimensional arrays (2 rows, 3 columns) (3 rows, 3 columns) 2-D arrays will not be discussed in this lecture 1.2 3.2 1.0 3.1 92 0.0 d - = 1 4 6 7 2 5 8 4 3 e =
E7 L3 5 One-dimensional arrays One-dimensional arrays Those that have one row or one column. Construction: Manual Incremental linspace transpose: zeros ones rand/randn

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 6 One-dimensional arrays – manual construction One-dimensional arrays – manual construction Row vectors: Syntax: [ element1 , element2 , ] >>r = [3,7,9] r = 3 7 9 , separates columns of an array [ starts the array ] ends the array [ ] 3 7 9 r =
E7 L3 7 One-dimensional arrays – manual construction One-dimensional arrays – manual construction Row vectors: Syntax: [ element1 element2 ] >>r = [3 7 9] r = 3 7 9 [ ] 3 7 9 r = columns can be separated by a space

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 8 One-dimensional arrays – manual construction One-dimensional arrays – manual construction Column vectors: Syntax: [ element1 ; element2 ; ] >>c = [3;7;9] c = 3 7 9 ; separates rows of an array [ starts the array ] ends the array 3 7 9 c     =      
E7 L3 9 Row vectors – incremental construction Row vectors – incremental construction >> r = 3 : 2 : 10 r = 3 5 7 9 Syntax: first element : increment : limit [3,5,7,9]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 10 Row vectors – incremental construction Row vectors – incremental construction >> r = 3 : 2 : 10 r = 3 5 7 9 9 2 10 + | last element + increment | > | limit |
E7 L3 11 Examples – incremental construction Examples – incremental construction first element : increment : limit >> A = 1:1:10 A = 1 2 3 4 5 6 7 8 9 10 >> B = 1:10 B = 1 2 3 4 5 6 7 8 9 10 (first element : limit)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L3 12 Examples – incremental construction Examples – incremental construction first element : negative increment : limit >> C = 10 : -2 : -5 C = 10 8 6 4 2 0 -2 -4 | last element + increment | > | limit |
E7 L3 13 Linspace Linspace

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/17/2011 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at Berkeley.

### Page1 / 49

Lecture_03_horowitz - 1 E7: INTRODUCTION TO COMPUTER E7:...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online