CS 100 M Lecture 16 - 16. Two-Dimensional Arrays Set-Up...

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

View Full Document Right Arrow Icon
16. Two-Dimensional Arrays Set-Up Rows and Columns Subscripting Operations Examples
Background image of page 1

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

View Full DocumentRight Arrow Icon
Simple Set-Up Examples >> A = [1 2 3; 4 5 6] A = 1 2 3 4 5 6
Background image of page 2
Simple Set-Up Examples >> A = zeros(3,4) A = 0 0 0 0 0 0 0 0 0 0 0 0
Background image of page 3

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

View Full DocumentRight Arrow Icon
Simple Set-Up Examples >> A = floor(100*rand(5,5)) A = 95 76 61 40 5 23 45 79 93 35 60 1 92 91 81 48 82 73 41 0 89 44 17 89 13
Background image of page 4
Simple Set-Up Examples >> A = [zeros(3,2) [1;2;3]] A = 0 0 1 0 0 2 0 0 3
Background image of page 5

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

View Full DocumentRight Arrow Icon
Simple Set-Up Examples >> A = [zeros(3,2) ; [1 2] ] A = 0 0 0 0 0 0 1 2
Background image of page 6
Rows and Columns 12 17 49 61 38 18 82 77 83 53 12 10 A: A is a 3-by-4 array: 3 rows 4 columns. row 1 row 2 row 3 col 4 col 3 col 2 col 1
Background image of page 7

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

View Full DocumentRight Arrow Icon
Subscripting 12 17 49 61 38 18 82 77 83 53 12 10 A: Individual entries: A(3,2)
Background image of page 8
Subscripting 12 17 49 61 38 18 82 77 83 53 12 10 A: An Entire Row: A(2,:)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Scaling a Row 12 17 49 61 10 20 30 40 83 53 12 10 A: A(2,:) = 10*A(2,:) 12 17 49 61 1 2 3 4 83 53 12 10 A: Before After
Background image of page 10
Subscripting 12 17 49 61 38 18 82 77 83 53 12 10 A: An Entire Column: A(:,3)
Background image of page 11

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

View Full DocumentRight Arrow Icon
Incrementing the Values in a Column 12 17 49 61 38 18 82 77 83 53 12 10 A: A(:,3) = A(:,3) + 1 12 17 50 61 38 18 83 77 83 53 13 10 A: Before After
Background image of page 12
Subscripting 12 17 49 61 38 18 82 77 83 53 12 10 A: A General Subarray: A(2:3,3:4)
Background image of page 13

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

View Full DocumentRight Arrow Icon
Zeroing a Subarray 12 17 49 61 38 18 82 77 83 53 12 10 A: A(2:3,3:4) = zeros(2,2) 12 17 49 61 38 18 0 0 83 53 0 0 A: Before After
Background image of page 14
Classical Double Loop Set-Up 11 21 31 41 12 22 32 42 13 23 33 43 A: for i=1:3 for j=1:4 A(i,j) = 10*j + i; end end
Background image of page 15

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

View Full DocumentRight Arrow Icon
Set-Up By Row 11 21 31 41 12 22 32 42 13 23 33 43 A: A = []; for i=1:3 v = [10 20 30 40] + i; A = [A ; v] end
Background image of page 16
Set-Up By Column 11 21 31 41 12 22 32 42 13 23 33 43 A: A = []; for j=1:4 v = 10*j + [1;2;3]; A = [A v] end
Background image of page 17

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

View Full DocumentRight Arrow Icon
A = [ 1 2 3; 4 5 6]; C = A(:,2); What the value of A(2,2)? A.
Background image of page 18
Image of page 19
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

CS 100 M Lecture 16 - 16. Two-Dimensional Arrays Set-Up...

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

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