{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter2-1d - Chapter2 MatlabBasics MatricesandVectors...

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

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

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

View Full Document Right 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)
Image of page 2
  Matrices These are two-dimensional arrays of  numbers Example  = 1 44 3 9 8 4 4 2 1 M
Image of page 3

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

View Full Document Right 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.
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.)
Image of page 5

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

View Full Document Right 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!
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
Image of page 7

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

View Full Document Right 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.
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)
Image of page 9

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

View Full Document Right Arrow Icon
Some Important Functions (3)
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern