Chapter2-1d

# Chapter2-1d - Chapter2 MatlabBasics MatricesandVectors

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

Chapter 2  Matlab Basics

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

View Full Document
Matrices and Vectors Arrays are chunks of data, frequently  indexed in several ways Lists of numbers, lists of names, Grade sheets, weather charts,  Medical records, wind-tunnel data Vector – 1 dimensional array (row or  column)
Matrices These are two-dimensional arrays of  numbers Example  = 1 44 3 9 8 4 4 2 1 M

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

View Full Document
MATLAB and Matrices One way you create a matrix in  MATLAB is by a statement like M=[1,2,3;2,3,5;2,33,2] or    M=[1 2 3;2 3 5;2 33 2] The comma (or space) separate entries  of a row, the semicolons separate rows.
More on Creating Matrices The colon can be used to create long lists of  numbers [row vector] x=a:b:c creates a list of numbers starting with  a, incrementing by b, ending at c Examples:  x=0:1:10  starts at 0, steps of 1, ends at 10 X=-3:.123:2; starts at –3, steps of .123,  ends at 2. (The semicolon suppresses the  echo.)

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

View Full Document
Still More on Creating  Matrices The colon can be used on matrices as  well: If M= [1,2,3;4,5,6;7,8,9] then  M(1:2,2:3) means the subarray of M  made up of rows 1 and 2, columns 2  and 3. Try it!
Creating String Arrays Strings are a sequence of characters delimited by single quotes (‘): ‘a’ ‘sam’ ‘1’ (not the same as the number 1) Example: >> couple='al n'' mary‘ (2 single quotes means a literal ') couple = al n' mary String arrays are created like matrices: >> M=['ab','cd';'ef','gh'] M = abcd efgh

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

View Full Document
Some Important Functions (1) size Size of array. D = size(X), for M-by-N matrix X, returns the two-element row vector D = [M,N] containing the number of rows and columns in the matrix. [M,N] = size(X) for matrix X, returns the number of rows and columns in X as separate output variables. length Length of vector. length(X) returns the length of vector X. It is equivalent to max(size(X)) for non-empty arrays and 0 for empty ones.
Some Important Functions (2) >> M = [1 2 3;4 5 6] M = 1 2 3 4 5 6 >> size(m) ans = 2 3 >> length(m) ans = 3 % largest dimension; if string, returns length of string (number of characters)

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

View Full Document
Some Important Functions (3)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/13/2010 for the course EGR EGR115 taught by Professor Newman during the Spring '10 term at Embry-Riddle FL/AZ.

### Page1 / 31

Chapter2-1d - Chapter2 MatlabBasics MatricesandVectors

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

View Full Document
Ask a homework question - tutors are online