{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_lecture3_F08 1D arrays-1

# E7_lecture3_F08 1D arrays-1 - 1 E7 INTRODUCTION TO COMPUTER...

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

1 E7: INTRODUCTION TO COMPUTER ROGRAMMING FOR SCIENTISTS AND PROGRAMMING FOR SCIENTISTS AND ENGINEERS Lecture Outline 1. Introduction to arrays 2. One-dimensional arrays 3. Character strings E7 L3 2 Introduction to arrays n rray an ordered collection of real numbers An array is an ordered collection of real numbers. ATLAB t t ffi i tl 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 xamples 1 imensional arrays: Examples 1-dimensional arrays: row 1 column) ] (1 row, 1 column) [1] a (1 row,4 columns) ! " 15 3 2 b # rows 1 column) 2 1 c \$% &' # ' E7 L3 (3 rows, 1 column) 3 ±) 4 Introduction to arrays xamples: 2 imensional arrays Examples: 2-dimensional arrays (2 rows, 3 columns) 1.2 3.2 1.0 3.1 92 0.0 d # ) (3 rows, 3 columns) 146 725 e ' (, ) 843 E7 L3 2-D arrays will not be discussed in this lecture

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

View Full Document
5 One One-dimensional arrays dimensional arrays hose that have one row r ne column Those that have one row or one column. t t i Construction: Manual Incremental linspace transpose: “’” zeros ones E7 L3 rand/randn 6 One One-dimensional arrays dimensional arrays – manual construction manual construction ow vectors: Row vectors: >>r = [3,7,9] !" 379 r r = 79 Syntax: [ element1 , element2 , … ] [ starts the array , separates columns of an array E7 L3 ] ends the array 7 One One-dimensional arrays dimensional arrays – manual construction manual construction ow vectors: Row vectors: >>r = [3 7 9] r r = Syntax: [ element1 element2 … ] olumns can be separated by a space E7 L3 columns can be separated by a space 8 One One-dimensional arrays dimensional arrays – manual construction manual construction olumn vectors: % Column vectors: >>c = [3;7;9] 3 7 c \$% &' ' c = 3 9 ±) Syntax: [ element1 ; element2 ; … ] 7 9 [ starts the array ; separates rows of an array E7 L3 ] ends the array
9 Row vectors Row vectors – incremental construction incremental construction >> r = 3 : 2 : 10 r = 3 5 7 9 [3,5,7,9] Syntax: rst element crement it E7 L3 first element : increment : limit 10 Row vectors Row vectors – incremental incremental construction construction (positive increment) >> r = 3 : 2 : 10 r = 3 5 7 9 921 0 last element + increment > limit E7 L3 11 Row vectors Row vectors – incremental incremental construction construction (positive increment) first element : increment : limit >> A = 1:1:10 A = 23456789 1 0 123456789 > = 1:10 >> B = 1:10 B = (first element : limit) E7 L3 1 2 3 4 5 6 7 8 9 10 12 Row vectors Row vectors – incremental incremental construction construction (negative increment) first element : negative increment : limit >> C = 10 : -2 : -5 C = 086420 2 5 , 10 8 6 4 2 0 -2 -4 42 5 ## # last element + increment < limit E7 L3

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

View Full Document
13 Linspace command lso creates a linearly spaced row vector also creates a linearly spaced row vector number of elements are specified instead of increment Syntax: linspace(x1,x2,n) 1 wer limit x1 lower limit x2 upper limit - umber of venly- paced lements n number of evenly spaced
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}