CS1371 Introduction to Computing for Engineers - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

CS1371 Introduction to Computing for Engineers

Description:

Big part of Matlabs power is operation on entire Arrays, both on an per element ... 'Mat'Lab is all about matrices originally that's all it was about. A Matrix ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 9
Provided by: david3049
Category:

less

Transcript and Presenter's Notes

Title: CS1371 Introduction to Computing for Engineers


1
CS1371Introduction to Computing for Engineers
  • Arrays(soon to be Matrices)

2
Administrivia
  • HW4 yes Web Work crashed. Extended to midnight
    tonight 6
  • Lab 1 posted due Friday.
  • Homework 5 Soon to be posted due next
    Thursday.
  • START THIS ONE EARLY TOO!!!!
  • Web page "Lectures" page has class schedule
    including all lecture topics and EXAM
    dates(first exam Sept 26th)
  • OK to send me email..
  • Reading
  • Arrays Smith, Chapter 11

3
Review Arrays
  • A Collection is a really a data structure into
    which you put stuff, and from which you get
    stuff.
  • Our basic (ie Matlabs) type of collection is
    called an Array.
  • Arrays are homogeneous collection of things.
  • All are the same
  • Are indexable
  • Example a text string is an array of characters
  • Big part of Matlabs power is operation on entire
    Arrays, both on an per element basis and in a
    summation like basis.
  • Each element of an array has a value (and a
    position).
  • A vector is an one dimensional array

4
Matrices Two Dimensional Arrays
  • MatLab is all about matrices originally
    that's all it was about.
  • A Matrix is a 2-D array. Behave like vectors but
    two dimensional. A deck of columns.
  • As an array, they are indexable and homogeneous
  • In some ways, just like vectors
  • Create, refer, subset
  • Scalar ops, logical ops
  • Per-element operations (.)
  • But arrays can be N-D

5
Array and Creation
  • Create 2-D arrays
  • A 1 2 3 4 5 6
  • A ones(4,6) four rows, 6 columns
  • A false(2,3) logical matrix (can also use
    for vectors)
  • ROWS and COLUMNS are the names of the dimensions.
    ROWS is always before COLUMNS (a 2 by 3 2
    rows, 3 cols)
  • Access by a(2,1) just like vectors a(r,c)
  • Show transpose operator A'
  • Useful creation rand(4,3) do more than once
  • Also zeros(r,c), and diag(A) (be careful here)

6
N-D arrays
  • Arrays can be N-D easiest to show N is 3
  • image zeros(16,16,3) rows, cols, planes
  • image(,,1) rand(16,16) floating point
    image
  • imshow(image) make sure showing color
  • image(,,2) rand(16,16) set 2D set of
    3Darray
  • image(,,3) .4
  • imshow(image)
  • Extraction
  • green (,,1) only a 2 D array.

7
Ops on 2-D arrays and matrices
  • Create an array B 5 4 9 10 11 12
  • Sum(a) doesnt do what you might think
  • Try max(a) gives max of each column why
    because matrix is really a stacking of vertical
    columns
  • Suppose grades of 6 students, four grads
  • gr rand(6,4) gives btw 0 and 1
  • if want 60 to 100 gr round( 60 40.gr) (round
    works on arrays)

8
Subsets on arrays
  • Gr(24,24) - gives subset
  • Gr(24) works but is not the right thing uses
    that linearization that's usually bad
  • If want rows 2 4
  • Gr(24,) gives all cols of the rows
  • Colon gives you the whole dimension
  • If just want the 4th column Gr(,4)
  • Odd columns gr(,12end)
  • Suppose CourseGr is section by student
  • CourseGr round( 40 60.rand(25,4))
  • Suppose passing gt60
  • Count of passing sum(sum(CourseGrgt60))
Write a Comment
User Comments (0)
About PowerShow.com