{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern