Vous êtes sur la page 1sur 85

-5

Rate of Change
Other Kinds of Arrays
Chapter 11
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Comparison of Double and Single Precision Calculations


18

Sum of the Harmonic Series


16

14

100
12

200
10
300

8
400

500
100 200 300 400 500
6
0 2000 4000 6000 8000 10000
Number of steps*1000

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or
transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
Objectives
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

After studying this chapter, you


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

should be able to:


• Understand the different kinds of data used in
MATLAB
100
• Create and use both numeric and character
200

300
arrays
400
• Create multidimensional arrays, and access
data in those arrays
500
100 200 300 400 500

• Create and use cell and structure arrays

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Section 11.1
Data Types
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• The primary data type (also called


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

a class) in MATLAB is the array or


matrix
100
• Within the array, MATLAB
200

300
supports a number of different
400

500
secondary data types (classes)
• The default is a double precision
100 200 300 400 500

floating point number

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
MATLAB’s arrays can store
different types of data
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

Kinds of Data Stored in MATLAB Matrices


0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Symbolic Objects -
Character Logical Numeric Symbolic Toolbox

100
Integer Floating Point
200

300

400

multiple multiple single double


500
100 200 300 400 500
signed integer unsigned precision precision
types integer types

complex real

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
There are a variety of array
types to store the data
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
MATLAB Array Types
time, hour

Character Logical Numeric Symbolic Cell Structure


Arrays Arrays Arrays Arrays Arrays Arrays

Most of these
arrays can
100

200
Integer Floating Point
300
only hold
400
information of
500
100 200
one data type
300 400 500
multiple multiple single double
signed unsigned precision precision
integer types integer types

Cell and Structure arrays can


MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
Other types, including user store
This material is is protected by Copyright and written permission should be obtained from the different
publisher types reproduction,
prior to any prohibited of data in thein a retrieval system,
storage
or transmission in anydefined and JAVA types
form or by any means, electronic,
same array
mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The difference between array


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

types and data types may be


confusing
100

200
• Consider the following analogy
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
There are lots of different places you
could store your wealth
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

They
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

correspond
to the
array types
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
There are lots of different kinds of
-5
Rate of Change

wealth you might store in a bank


Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

They
correspond to
the data types
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Numeric Data Types
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Numeric data is stored in numeric


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

arrays
time, hour

• The default data type is double


precision floating point
100
• Every time you enter a number into
200 MATLAB, the program assumes
300

400
you’ve entered a double
500
100 200 300 400 500
• MATLAB conforms to the IEEE
standards that specify the meaning of
the double data type

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
When you define numeric
-5
Rate of Change

values they default to doubles


Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Each value in a double


array needs 8 bytes of
memory to store
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5
There are 6 values in the C
-2

-1.5

-1
array – therefore it requires
-0.5

0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
6 x 8 = 48 bytes of memory

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Value limitations
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The biggest number you can store


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

in a double can be found using


the realmax function
100

200
• The smallest number you can
300

400
store in a double can be found
500
100 200 300 400 500
using the realmin function

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Single Precision floating
point numbers
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Uses half the storage space of a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

double
• Each value requires
100

200
• 4 bytes = 32 bits
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100
The grid symbol indicates a numeric
200 array – double, single or integer
300

400

500
100 200 300 400 500 It’s necessary to use the
single function to change
the value of 5 (which is a
double by default) into a
single
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Value limitations
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Since single precision numbers are


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

allocated only half as much storage


space, they can not cover as large a
range of values as double numbers
100 • The biggest number you can store in a
200
single can be found using the
realmax(‘single’) function
300

400

500
100 200 300 400 500
• The smallest number you can store in a
double can be found using the
realmin(‘single’) function

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
• Engineers will rarely
Rate of Change
need to convert to
single precision
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

numbers, because
-3

-2.5

-2

-1.5

• today’s computers
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

have plenty of
storage space for
most applications,
• and will execute
100 most of the
200
problems we pose in
extremely short
300

400

500
100 200 300 400 500
amounts of time

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
When would you use the short data
-5
Rate of Change

type instead of double values?


Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• In some numerical analysis


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

applications you may be able to


improve the run time of a long
100
problem by changing from double
to single precision
200

300

400

500
100 200 300 400 500
• However, round off error becomes
more of a problem.

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Consider the harmonic
series
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

1/1 1/ 2 1/ 3 1/ 4 1/ 5 1/ 6  ... 1/ n + ...


0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour



100 n 1
1 / n Shorthand for the harmonic series

200

300

400
This series diverges -it just keeps getting
500

bigger the more terms you add


100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
For large numbers of steps the results
are different using double and single
Rate of Change

data types
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Comparison of Double and Single Precision Calculations


18
double
Sum of the Harmonic Series
16

14
100
single
200
12
300

10
400

500
100 200 300 400 500
8

6
0 2000 4000 6000 8000 10000
Number of steps*1000

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Why?
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• When the series gets big enough the


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

value of 1/n is so small that the


computer can’t distinguish it from 0
• This occurs at the value of realmin
100

200

300
• Since doubles can differentiate
400

500
between smaller numbers than singles
the summation is valid for more steps
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Each of these
types require a
-5
Rate of Change Integers different amount
of storage
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Integer arrays are new to MATLAB 7


-1.5

-1

-0.5

• Integers are stored in integer arrays


0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

MATLAB Integer Types


8-bit signed Remember
int8 that unsigned
8-bit 8 bits = 1integer
byte uint8
integer
100

200
16-bit signed int16 16-bit unsigned uint16
300
integer integer
400

500
32-bit signed int32 32-bit unsigned uint32
100 200 300 400 500

integer integer
64-bit signed int64 64-bit unsigned uint64
integer integer

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
You can determine the number of
possible values allowed in the
Rate of Change

integer data type


-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Each of the integer types uses a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

different amount of storage, and


can thus save different ranges of
100
values
• Determine the size range using
200

300

400

500
100 200 300 400 500
• intmax and intmin

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
When do we use integers
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Integer arrays can be used to store


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

image information
• These arrays are often very large, but
there are a limited number of colors
100
used in many of these images to
create the picture.
200

300

• Storing them as unsigned integer


400

500
100 200 300 400 500

arrays reduces the storage


requirement dramatically.

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Complex numbers
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Default is double
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Twice as much storage is needed


because the real and imaginary
100

200
components must be stored
300

400
• Could also be stored as a single
500
100 200 300 400 500

or integer

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Character and String Data
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Character arrays store character


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

information
• A character array is produced
100

200
from a string
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Each character is a separate


element in the array
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

The fifth element of the H array is the


letter y
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Any string represents a character


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

array in MATLAB
• Each character requires 2 bytes of
100

200
storage
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

The ‘ab’ symbol indicates a


100
character array
200
Spaces are characters too
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
How are characters stored in
MATLAB?
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• All information in computers is


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

stored using a series of zeros and


ones
• ASCII – Used in small computers
• EBCDIC – Used in mainframes and
100

200

super computers
300

400

• You can think of this list of 0’s and


500
100 200 300 400 500

1’s as a base two number

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Comparison between base 2
and base 10
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

Base 2 ”binary”
-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Base 10
”decimal”
time, hour

1 1
10 2
100
11 3
200
100 4
300

400 101 5
500
100 200 300 400 500

110 6
111 7
1000 8

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Every character stored using ASCII or


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

EBCDIC code has both a binary


representation and a decimal
equivalent
• When we ask MATLAB to change a
100

200

character to a double, the number we


300

400

500
100 200 300 400 500

get is the decimal equivalent in the


ASCII coding system

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
MATLAB includes functions
to change data types
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Use the double


function to convert to a
double precision
floating point number

100

200

300
Use char to convert a
400
number to a character
500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
You shouldn’t mix data types
-5
Rate of Change

in calculations or in arrays
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

If you attempt to create


an array with both Notice that the ans array
100 character and numeric has two characters
200
data, the array defaults
300
to all characters
400

500
100 200 300 400 500

There is no character
equivalent to 3, so
MATLAB adds a space
to the array
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
If you try to perform
arithmetic with a
combination of
character and numeric
data, MATLAB converts
the character to its
100
decimal equivalent
200

300

400

500
100 200 300 400 500
Remember that a has a
decimal equivalent of
97

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Symbolic Data
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Covered in more detail in a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

separate chapter
• The symbolic toolbox uses
100

200
symbolic data to perform symbolic
300

400
algebraic calculations
500
100 200 300 400 500

• Create a symbolic variable using


the sym function

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

The cube symbol


100 indicates a symbolic
200
array
300

400

500
100 200 300 400 500

Symbolic variables can be grouped


into arrays, just like other data types
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Logical Data Types
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Logical data can have only one of


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

two values
• True
100
• False
200

300

400
• MATLAB uses
• 0 to represent false and
500
100 200 300 400 500

• 1 to represent true

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Although a logical array contains the The check mark


information true and false, MATLAB indicates a logical array
100
represents it as 0 and 1
200

300

400 We don’t usually create logical arrays


500
100 200 300 400 500 by entering true and false values.
Usually they are the result of logical
operations

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Notice that x and y are


100
We can interpret this result to mean numeric arrays and z is a
200
that x>y is false for elements 1 and 3, logical array
300 and true for elements 2,3 and 5
400

500
100 200 300 400 500

These arrays are used in logical


functions, and are not usually even
seen by the user.

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

In this example the find command used


the result of the comparison x>y to
determine that elements 2, 3, and 4 met
the criteria

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Sparse Arrays
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Both double precision arrays and


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

logical arrays can be stored in either


full matrices, or as sparse matrices.
• Sparse matrices are “sparsely
populated”, meaning many or most of
100

200

the values in the array are zero


300

400

• Identity matrices are examples of sparse


500
100 200 300 400 500

matrices

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Sparse matrices require less space
than the corresponding numeric or
logical matrices
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• If we store sparse arrays in the full


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

matrix format, it takes 8 bytes of


storage for every data value,
whether they are zeros or not
• The sparse matrix format only
100

200

300

400
stores the non-zero values, and
remembers where they are
500
100 200 300 400 500

• this strategy saves a lot of space

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

N is a 1000x1000 identity
Compare the size of N and P
matrix
100

200

300
P is the same matrix, stored
400
using the sparse strategy
500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Section 11.2
Multidimensional Arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Sometimes you may want to store


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

data in multidimensional arrays


• Rows
100
• Columns
200

300

400
• Pages
500
100 200 300 400 500
• Additional dimensions are possible

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Multidimensional arrays are
grouped into pages
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

columns

100

200

300
rows pages
400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

Page 1
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Page 2
100

200

300
Page 3
400

500
100 200 300 400 500

Page 4 Imagine that you


would like to store
each of these 4 two-
dimensional arrays
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
into 1 three-
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

dimensional array
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

You must define each page


200

300

400
separately. Read the first
500
100 200 300 400 500
definition statement as
“all the rows, all the
columns, in page 1”

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Section 11.3
Creating Character Arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• We can create two dimensional


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

character arrays only if the


number of elements in each row is
100
the same
200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

This statement doesn’t work, because


the number of characters in each line
is different
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

The char functions “pads” the array with


blanks. Notice that the array size is 6
100
rows by 7 columns
200

300

400

500
100 200 300 400 500

Character arrays can store any of the


characters defined in the ASCII coding
scheme – including the symbols for
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
numbers
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Character arrays can only
hold character data
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• We can take advantage of this to


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

create tables that look like they


include both character and
100
numeric information, but really are
composed of just characters
200

300

400

500
100 200 300 400 500
• The number 1 is different from the
character 1

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Let’s combine an array of
test scores and names
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Test scores • Names


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• 98 • Holly
• 84 • Steven
• 73 • Meagan
• •
100

200 88 David
• •
300

400
95 Michael
• 100 • Heidi
500
100 200 300 400 500

Numeric information Character information

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Notice that table is a


character array
100

200

300
When we tried to store the
400
two different data types into
500
100 200 300 400 500
the same array, MATLAB
interpreted the numbers as
the ASCII equivalent of
characters

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change num2str
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• In order to store the two different


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

data types in the same array, we’ll


need to convert the numbers into
100
the corresponding characters
• num2str
200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500
The num2str function converted
the array of scores into the
corresponding characters

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Creation of file names
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• A useful application of character


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

arrays and the num2str function


is the creation of file names
100
• There are occasions when you
200
may want to save data into .dat or
.mat files, but you don’t know
300

400

ahead of time how many files will


500
100 200 300 400 500

be required my_data1.dat
my_data2.dat
my_data3.dat
Etc.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change For example….
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Load a file of unknown size called


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

some_data
• Create a number of new files, one
100

200
for each column from the input file
300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Input and Output
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5
Output files
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Data from input file
time, hour

Data in File1
Data in File2
1 2 3 1 Data in File3
2
4 5 6 4 3
100
5
200

7 8 9 7 6
8
300

400

500
100 200 300 400 500
10 11 12 10 9
11
12

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Load the input file


Determine the
number of rows
and columns
100

200
Extract the
300
data
400
Create the file
names
500
100 200 300 400 500

Save the data


into the new
files

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Section 11.4
Cell Arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The cell array can store different


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

types of data inside the same


array
100

200
• Each element in the array is also
300

400
an array
500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200 These three arrays all store


300
different data types
400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

Create a cell array using curly braces

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Indexing
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• The indexing system used for cell


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

arrays is the same as that used in


other arrays.
• You may either use a single index, or a
100
row and column indexing scheme.
• There are two approaches to retrieving
200

300

information from cell arrays.


400

500
100 200 300 400 500

• Parentheses – results in a description


• Curly braces – results in the values

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

To access a particular element inside an


array stored in a cell array, you must use
a combination of curly braces and
parentheses
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Section 11.5
Structure Arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Similar to Cell Arrays


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Multiple arrays of differing data


types can be stored in structure
100

200
arrays
300

400
• Instead of using content indexing
500
100 200 300 400 500

each of the matrices is given a


location called a field

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200
This is still a 1x1
300 structure array –
400
however it has three
500
100 200 300 400 500
fields

This structure array (struct)


MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
contains three fields
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400
We can add more content to the
500
100 200 300 400 500
structure, and expand its size, by
adding more matrices to the
fields we’ve defined.

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
You can access the
information using…
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Matrix name
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Field name
• Index numbers
100

200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200
Just calling the matrix name
300
returns a description of the
400 array
500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

You can access the actual arrays you’ve


stored in the structure by using an index
number to identify which set of data you’re
interested in
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100
You can use the field name to access
200 just the data in certain fields. This
300
example returns the arrays in the first
400
field of each member of the structure
500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500

Combining an index number and


100 200 300 400 500

the field name allows you to


access one particular array

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

100

200

300

400

500
100 200 300 400 500

Finally, if you want to know the content of one


particular element in a field you must specify
the element index number after the field
name. MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Variable Editor
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• You can use the


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

variable editor to
access the
content of a
100
structure array
• Double click the
200

300

400

500
structure array
name in the
100 200 300 400 500

workspace
window
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• If you double click on one of the


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

elements of the structure in the


variable editor, the editor expands
100
to show you the contents of that
element
200

300

400

500
100 200 300 400 500

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• MATLAB’s primary data structure is


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

the array
• MATLAB supports a number of
different array types, each of which
100

200 can store a particular type of data


300

400

500
• Cell and structure arrays can store
more than one data type in the same
100 200 300 400 500

array

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary-Data Type
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• MATLAB supports the following data


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

types
• Numeric
• double
100
• single
200

300
• 8 different types of integers
• Character
400

500
100 200 300 400 500

• Symbolic
• Logical

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change Summary - Array Types
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Numeric
-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• double
• single
• 8 different integer arrays
• Character
• Symbolic
100

200

300

400
• Logical
500
100 200 300 400 500 • Sparse
• Cell
• Structure

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Summary –
Multidimensional Arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Additional dimensions can be


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

stored in MATLAB arrays


• The third dimension is called a
100

200
page
300

400
• Each page must be entered
500
100 200 300 400 500

separately as a two-dimensional
array

MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system,
or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write to: Rights and
Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Vous aimerez peut-être aussi