E7_Lecture5_Su10+posted

E7_Lecture5_Su10+posted - Introduction to arrays Examples:...

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

View Full Document Right Arrow Icon
E7 L3 1 Introduction to arrays Introduction to arrays Examples: 2-dimensional arrays (2 rows, 3 columns) (3 rows, 3 columns) 1.2 3.2 1.0 3.1 92 0.0 d - = 1 4 6 7 2 5 8 4 3 e =
Background image of page 1

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

View Full DocumentRight Arrow Icon
E7 L4 2 2-dimensional arrays 2-dimensional arrays A rectangular arrangement of numbers is called an array. 2 1 2 4 5 - Example: 3-by-2 array. (3 rows, and 2 columns) (3,1) element (3 rd row, and 1 st column) Matlab 2-D convention: ( Row , Column)
Background image of page 2
E7 L4 3 Creating arrays – manual construction Creating arrays – manual construction Example 1: >> A = [ 2 1 ; -2 3 ; 4 5 ] A = 2 1 -2 3 4 5 2 1 2 3 4 5 A = - The semicolon is used to demark rows
Background image of page 3

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

View Full DocumentRight Arrow Icon
E7 L4 4 Creating arrays – manual construction Creating arrays – manual construction Example 1: carriage return <CR> is also used to demark rows >>A = [ 2 1 -2 3 4 5 ] A = 2 1 -2 3 4 5
Background image of page 4
Example 1: >>A = [[ 2 ; -2 ; 4 ] , [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 5 Creating arrays – manual construction Creating arrays – manual construction first column second column
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example 1: >>A = [[ 2 ; -2 ; 4 ] [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 6 Creating arrays – manual construction Creating arrays – manual construction first column second column comma is not needed
Background image of page 6
Example 1: >> A = [[ 2;-2 ;4 ] . .. [ 1 ; 3 ; 5 ] ] A = 2 1 -2 3 4 5 E7 L4 7 Creating arrays – manual construction Creating arrays – manual construction “...” - allows a new line without a <CR>
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example 1: >>A = [[ 2;-2 ;4 ] [ 1 ; 3 ; 5 ] ] A = 2 -2 4 1 3 5 E7 L4 8 Creating arrays – manual construction Creating arrays – manual construction <CR> means a new row
Background image of page 8
zeros, ones and rand commands zeros, ones and rand commands E7 L3 9 >> A = ones(2,3) A = 1 1 1 1 1 1 >> B = zeros(2,2) B = 0 0 0 0 Matlab 2-D convention: >> r = 3*ones(1,5) r = 3 3 3 3 3 (rows, columns)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Array concatenation Array concatenation E7 L3 10 >> A = ones(2,3) A = 1 1 1 1 1 1 >> B = zeros(2,2) B = 0 0 0 0 >> C = [ A B ] C = 1 1 1 0 0 1 1 1 0 0
Background image of page 10
Array concatenation Array concatenation E7 L3 11 >> C = [ A B ] C = 1 1 1 0 0 1 1 1 0 0 C is the array formed by stacking A “next to” B Once constructed, C does not “know” that it came from two arrays. No partitioning information is maintained.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Array concatenation Array concatenation E7 L3 12 C = 1 1 1 0 0 1 1 1 0 0 r = 3 3 3 3 3 >> D = [ C ; r ] D = 1 1 1 0 0 1 1 1 0 0 3 3 3 3 3
Background image of page 12
Array concatenation Array concatenation E7 L3 13 >> D = [ C ; r ] D = 1 1 1 0 0 1 1 1 0 0 3 3 3 3 3 D is the array formed by stacking C “on top of” r
Background image of page 13

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

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at University of California, Berkeley.

Page1 / 41

E7_Lecture5_Su10+posted - Introduction to arrays Examples:...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online