Chapter2-1d - Chapter2 MatlabBasics MatricesandVectors

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

View Full Document Right Arrow Icon
       Chapter 2  Matlab Basics
Background image of page 1

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

View Full DocumentRight Arrow Icon
  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)
Background image of page 2
  Matrices These are two-dimensional arrays of  numbers Example  = 1 44 3 9 8 4 4 2 1 M
Background image of page 3

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

View Full DocumentRight Arrow Icon
  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.
Background image of page 4
  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.)
Background image of page 5

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

View Full DocumentRight Arrow Icon
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!
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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.
Background image of page 8
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)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Some Important Functions (3)
Background image of page 10
Image of page 11
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 Right Arrow Icon
Ask a homework question - tutors are online