17. Matrices in Matlab

17. Matrices in Matlab - ENGR 101 Section 100 Fall 09...

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

View Full Document Right Arrow Icon
ENGR 101, Section 100, Fall 09 1 Matrices in MATLAB ENGR 101, Lecture 17: 15 Nov 10 Announcements Look for Project 7 this week (due Wed 1 Dec) First MATLAB assignment
Background image of page 1

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

View Full Document Right Arrow Icon
ENGR 101, Section 100, Fall 09 2 MATLAB Data Elements (review) all data is some kind of array. Scalars : arrays with one element (zero dimensions) myscalar = 34.2; Vectors : sequence of scalars (one dimension, row or column) myvector = [ 34.2 19 1.24 ]; Matrices : two or more dimensions (rows, columns, …) mymatrix = [ 34.2 19 1.24 1286 19.001 0 ]; Character and String Literals Enclosed in single quotes 'M' 'Michigan' 'ann arbor' '2010' % not the number 2010 String is a vector of characters ['a' 'n' 'n'] 'ann' 'a':'f' 'abcdef' 'a':2:'k' 'acegik' 'A':'z'
Background image of page 2
ENGR 101, Section 100, Fall 09 3 Colon Operator for Matrices M = [ 1:5; 3:3:15; 6:10 ] [1 2 3 4 5 3 6 9 12 15 6 7 8 9 10 ] M(2,4) 12 M(2,2:3) [6 9] M(1:2,2:3) [2 3; 6 9] M(3,:) [6 7 8 9 10] M(:,2) [2 6 7]' Assigning to Index Ranges M = [ 1:5; 3:3:15; 6:10 ] [1 2 3 4 5 3 6 9 12 15 6 7 8 9 10 ] M(2,2:3) = [66 99] M(1:2,4:5) = -1 M(3,:) = 66:70 M(:,2) = [5 5 5]
Background image of page 3

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

View Full Document Right Arrow Icon
ENGR 101, Section 100, Fall 09 4 Appending Arrays MATLAB flattens array sequences Examples: [10 [20 30] [40 [50 60]]] [10 20 30 40 50 60] [1:3 1:3] [1 2 3 1 2 3] [1:3'; 4:6'] 1:6' [1:3' 4:6'] [ 1 4 2 5 3 6 ] Deleting Array Elements Assign empty array Examples: v = 1:10 M = [1:5; 11:15; 21:25] v(4) = [] % deletes fourth elt v(3:5) = [] % deletes 3d through 5th elts M(:,2) = [] % deletes 2d column M(1,:) = [] % deletes 1 st row
Background image of page 4
ENGR 101, Section 100, Fall 09 5 Built-In Matrix Creation Functions zeros(n) creates an n × n matrix of zeros zeros(n, m) creates an n × m matrix of zeros ones(n) creates an n × n matrix of ones ones(n, m)
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 14

17. Matrices in Matlab - ENGR 101 Section 100 Fall 09...

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

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