E77: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND ENGINEERS - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

E77: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND ENGINEERS

Description:

in the Farenheit scale to temperatures in the Celcius scale. What is the conversion rule? ... employed to input, manipulate and output arrays. ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 11
Provided by: pack3
Category:

less

Transcript and Presenter's Notes

Title: E77: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND ENGINEERS


1
E77 INTRODUCTION TO COMPUTER PROGRAMMING FOR
SCIENTISTS AND ENGINEERS
  • Lecture Outline
  • 1. Introduction to arrays
  • 2. One-dimensional arrays
  • 3. Character strings

2
Introduction to arrays
  • 1. Introduction to arrays
  • A simple array is an ordered collection of real
    numbers.
  • MATLAB treats arrays as a particular data type
    and
  • handles them very efficiently, in terms of
  • Input/output, indexing and addressing
  • Arithmetic operations
  • Other manipulations (e.g., sizing, reshaping,
    etc.)
  • Arrays are the primary building blocks in MATLAB.

3
Introduction to arrays
  • Examples

  • (1 row, 1 column)

  • (1 row,4 columns)

  • (3 rows, 1 column)

  • (2 rows, 3 columns)

4
One-dimensional arrays
  • 2. One-dimensional arrays
  • Consider first one-dimensional simple arrays,
    i.e., those
  • that have one row and/or one column.
  • Construction (manual, incremental, linspace,
  • zeros,ones,rand,randperm)
  • Addressing (), sizing (length)
  • Manipulation (transposition, concatenation,
    row/column addition)
  • Arithmetic operations (scalar addition/multiplicat
    ion,
  • array addition/multiplication, array
    exponentiation)

5
One-dimensional arrays
  • Example
  • Convert a one-dimensional array containing
    temperatures
  • in the Farenheit scale to temperatures in the
    Celcius scale.
  • What is the conversion rule?

6
One-dimensional arrays
  • Example
  • Convert a one-dimensional array containing
    temperatures
  • in the Farenheit scale to temperatures in the
    Celcius scale.
  • What is the conversion rule?

7
Character strings
  • 3. Character strings
  • In addition to numbers, many computer programs
    also
  • need to deal with text data, e.g.,
  • Names and addresses
  • Input and output prompts
  • Labels
  • Text files
  • Character strings in MATLAB are special arrays
    displayed
  • in text format, but stored and manipulated in
    numerical
  • format.

8
Character strings
  • How are strings implemented in MATLAB?
  • Construction (' ')
  • Conversion to numbers (double) and vice-versa
    (char)
  • MATLAB recognizes 256 characters
  • Addressing, sizing and searching (findstr)
  • Manipulation (transposition, reversal,
    concatenation,
  • upper-/lowercase conversion)
  • String arrays

9
One-dimensional arrays
  • Example
  • Manipulate the roster of E77
  • Name matching (strmatch)
  • Reverse the alphabetical order of the classlist
  • Order classlist randomly
  • Can everyone make an A in this class?

10
Summary
  • What did we learn today?
  • Arrays are important data structures and can be
  • treated with great efciency in MATLAB.
  • Many different MATLAB built-in functions can be
  • employed to input, manipulate and output arrays.
  • Strings are numerical arrays in disguise and are
  • employed to treat text data.
  • Many different MATLAB built-in functions can be
  • employed to input, manipulate and output strings
    and
  • string arrays.
Write a Comment
User Comments (0)
About PowerShow.com