Arrays-by Toshant - Arrays 1. Arrays vs. Vectors a. All...

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

View Full Document Right Arrow Icon
Arrays 1. Arrays vs. Vectors a. All vectors are pretty much just one row/column arrays. 2. Creating Arrays and Array Properties a. Arrays must be rectangular. They cannot be jagged. a.i. Meaning that if row 1 has two values, row 2 must also have two values. a.ii. If you try to make a jagged array, Matlab will either error or fill in the empty spot with zeros, depending on the command. b. Creating Arrays b.i. Direct Creation b.i.1. Arr = [1 2; 3 4; 5 6] -> Creates a vector of three rows and two columns. b.i.1.a. The semicolon creates vertical concatenation. So it creates the vectors [1 2], [3 4], and [5 6] and then places them on top of each other. b.i.1.a.i. Notice, if you want to vertically concatenate items, they must have the same number of rows. b.ii. Functions b.ii.1. Colon operator (:) and linspace cannot create an array. They can only create vectors. b.ii.1.a. You might have to get crafty to place these values in an array. b.ii.2. ones, zeros, and rand Functions b.ii.2.a. All of these functions take two inputs ( row , col ). b.ii.2.b. So, row refers to the number of rows, and col refers to the number of columns. b.ii.2.b.i. Remember how when we created a vector, we would do (1, 4) to create a vector of 4 values. b.ii.2.c. x = ones(7, 4) b.ii.2.c.i. The code above creates an array of ones. The array has 7 rows, and 4 columns. c. Accessing and Indexing Arrays c.i. Note : Most rules of Vector indexing rules apply to arrays. (Can't index out of bounds, but you can assign out of bounds, etc. Read up on vector notes for full rules) c.ii. Basics of Array Indexing c.ii.1. Arrays are indexed using the row and column references. c.ii.2. Assume: arr = [1 2; 3 4; 5 6]; c.ii.3. x = arr(3, 2) c.ii.3.a.The code above gets the value that's stored in the 3rd row and 2nd column. c.ii.3.b. x -> 6 c.ii.4. x = arr(7, 2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
c.ii.4.a.So we're going to the 7th row of arr, and the 2nd column. But the 7th row does not exist. c.ii.4.b. Therefore, Matlab will error. d. Shorthand Operators d.i.1. end operator d.i.1.a. In vectors, indexing with end references the end position of the vector. d.i.1.b. In arrays, the end position references the last position of the array in the reference position. d.i.1.b.i. x = arr(end, 1) d.i.1.b.i.1. The code above goes to the end row position and 1st column. d.i.1.b.ii. x = arr(1, end) d.i.1.b.ii.1. The code above goes to the end column, aka the last column, and the 1st rwos. d.i.1.b.iii. x = arr(end, end) d.i.1.b.iii.1. The code above goes to the end column and end row, so the last column and last row. d.i.2. Colon Operator d.i.2.a. In vectors, we used the colon operator to get more than one value. That same logic can be applied to the row and column assignments of an array.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2012 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Page1 / 8

Arrays-by Toshant - Arrays 1. Arrays vs. Vectors a. All...

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

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